I currently have a project in Ruby on Rails running Ruby 1.8.7 and Rails 2.3.2
I have some unit tests that read data from a database, specifically a date time column for two consecutive items which are supposed to be 24 hours apart. In one test I am setting the datetime for item 2 equal to that of item 1.
When I do an assert to make sure the two values are equal, the test works fine under rails 2.3.2. When I upgrade to rails 2.3.11, the tests fails showing that the difference between the two times to be off with the following error:
<Thu, 01 Jan 2009 06:00:00 CST -06:00> expected but was
<Thu, 01 Jan 2009 05:59:59 CST -06:00>.
There seems to be an issue with floating point conversions in the two version of rails. How can I account for the floating point issue?
This has happened to me too, and I ended up doing this:
datetime.should be_a(Datetime) # maybe unnecessary
datetime.to_s.should == expected_datetime.to_s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With