confirmed_at should have been changed to Mon, 24 Mar 2014 09:47:22 UTC, but is now Mon, 24 Mar 2014 09:47:22 UTC

Investigation

Time

> t1, t2 = Time.now, Time.now => [2014-03-27 23:19:18 UTC, 2014-03-27 23:19:18 UTC]

> t1 == t2 => false

Time

to_f

t1

t2

> t1.to_f => 1395955158.547284 > t2.to_f => 1395955158.547298

to_r

> t1.to_r => (348988789636821/250000) > t2.to_r => (697977579273649/500000)

Summary

to_i

> t1.to_i == t2.to_i => true

Time

> Time.at(t1.to_i) == Time.at(t2.to_i) => true

I believe every ruby developer has faced time comparison issue at least once and tests are one of the possible areas where it may happen. RSpec message like this may confuse:What’s wrong?Let’s create twoobjects:At the first glance, they are equal. But it’s not true:The issue occurs because rubymakes comparison with fractions of seconds. We may usemethod to see the difference betweenandormethod to get rational numbers:If you don’t care about milliseconds, you may compare timestamps usingmethod:or make a newobject from timestamps to have better RSpec failure messages:But even better to use fixed times in our tests.