Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.4.5 changed timezone comparison behavior #35

Closed
jjb opened this issue Aug 11, 2012 · 5 comments
Closed

0.4.5 changed timezone comparison behavior #35

jjb opened this issue Aug 11, 2012 · 5 comments

Comments

@jjb
Copy link

jjb commented Aug 11, 2012

this spec:

Timecop.freeze(@t = Time.now)
expect{
  # code...
}.to change(@object, :attribute).from(nil).to(@t)

used to pass with 0.4.4, but now fails with 0.4.5, with the message:

attribute should have been changed to 2012-08-10 23:10:57 -0400, but is now Sat, 11 Aug 2012 03:10:57 UTC +00:00

If I use pry to set a breakpoint with 0.4.4 and 0.4.5, I observe:

  • @t.to_f and @object.attribute.to_f are indeed identical as they should be
  • the timezones for each object are the same with both versions.

So, my guess: pry is doing its timefreezing job, and the Time objects are the same, but for some reason the comparison is now taking the timezone into consideration where before it was not. Is this expected/possible?

@travisjeffery
Copy link
Owner

I can't say for sure without seeing that code block or a reproduced failing test.

@ches
Copy link

ches commented Aug 12, 2012

From the test's inspect output, it looks like you're comparing a Time (from Time.now) with an ActiveSupport::TimeWithZone, and your development system's zone is different from the app's configured default. Likely you just need to use Time.zone.now.

@travisjeffery
Copy link
Owner

Agreed @ches, the only change in 0.4.5 was to make time instance type consistent for comparisons so if you're having a problem now it's likely because you were comparing instances inconsistently before.

@jjb
Copy link
Author

jjb commented Oct 8, 2012

I just discovered that my use of Timecop was incorrect, and that is probably what was causing this problem. I didn't know that I had to do Timecop.return, for some reason I assumed that it did its own cleanup at the end of an rspec example.

The top example in the Readme is good and clear, so I'm not sure where I got the idea. But I'll submit a tweak to the other example in the readme just in case others run into the same problem.

Thanks for Timecop!!

@jjb
Copy link
Author

jjb commented Oct 8, 2012

ack, i take it back, that wasn't what caused my issue. I'm still having the issue, and Time.zone.now didn't help. it did however make the output more consistent. comparing time Time objects i get:

foo_at should have been changed to Mon, 08 Oct 2012 16:31:55 UTC +00:00, but is now Mon, 08 Oct 2012 16:31:55 UTC +00:00

(they are identical)

suspecting that the difference is sub-second, I switched the comparison to to_f of the Time objects in order to get more meaningful failure output. however the result was that the specs now pass. the same with to_i.

/cc @ches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants