Tim Scott
Tim Scott

Reputation: 15205

Ruby 2.0 Breaking Change? Date Comparison

Heroku is saying that Ruby 2.0 is ready for production. Okay, I'll update my app. But my tests break. This one started failing:

a_date.should == the_same_date

The dates are equal. How do I know, besides that the same test passes under Ruby 1.9.3? This passes under 2.0:

a_date.to_i.should == the_same_date.to_i

Is this a bug in Ruby 2.0? I can't find anything about breaking changes to date equality.

UPDATE

Here is the actual test output:

Failure/Error: target.should == @now
  expected: Mon, 24 Jun 2013 15:40:52 UTC +00:00
  got:      Mon, 24 Jun 2013 15:40:52 UTC +00:00 (using ==)

Upvotes: 1

Views: 250

Answers (1)

Tim Scott
Tim Scott

Reputation: 15205

It was a problem with TimeCop; I think this one. In any case, switching to the head version solved the problem.

The problem was caused by freezing the time as Time.current. The two times were off by a single millisecond. Instead of comparing #to_i as I mention above, I should have compared #to_f.

Upvotes: 1

Related Questions