1

I have the following test:

it 'gives the correct last parsed result' do
 expect(FactoryGirl.create(:category_page_with_parsed_results).last_parsed_result.date).to eql(Date.parse('2012-01-01'))
end

And it fails like this:

 expected: Sun, 01 Jan 2012
 got: Sun, 01 Jan 2012 00:00:00 UTC +00:00

The thing here is that when I create that Factory, I don't write any 00:00:00 time at all, so I don't know why is it returning it that way.

Any thoughts on how should I test this?

3
  • does last_parsed_result is in timestamp, to be specific what is its class ? Commented Feb 26, 2014 at 16:30
  • Its class is: ActiveSupport::TimeWithZone Commented Feb 26, 2014 at 16:37
  • created a new answer, didn't tested it. give a try. May be that will work. Commented Feb 26, 2014 at 16:40

2 Answers 2

2

ok, do this

expect(FactoryGirl.create(:category_page_with_parsed_results).last_parsed_result.to_date).to eql(Date.parse('2012-01-01'))
Sign up to request clarification or add additional context in comments.

Comments

0

So I'm guessing your "last_parsed_result" object has a date property that is stored in the database. Playing around in irb (Ruby 2.1.0) console I have:

require 'date'
Date.parse('2012-01-01').to_s  => "2012-01-01"
DateTime.parse('2012-01-01').to_s => "2012-01-01T00:00:00+00:00"

My guess is that last_parsed_result.date is a DateTime object and so that's why you're getting the 00:00:00 time.

1 Comment

Mmmm but how do I test they are equal?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.