Using assert_equal
to compare dates will fail becuase they'll be off my a few miliseconds.
date = 1.month.from_now
travel_to date
@post.update(title: "Updated Title")
assert_equal date, @post.updated_at
# => No visible difference in the ActiveSupport::TimeWithZone#inspect output
Using assert_in_delta
to compare dates ensures the two values are within 0.001
seconds of each other by default.
date = 1.month.from_now
travel_to date
@post.update(title: "Updated Title")
assert_in_delta date, @post.updated_at
# => Expected |2021-11-25 14:53:58 UTC - 2021-11-25 14:53:58 UTC| (0.528975) to be <= 0.001.
If you need to increase the delta just pass it in as a third argument.
date = 1.month.from_now
travel_to date
@post.update(title: "Updated Title")
assert_in_delta date, @post.updated_at, 0.75
# => true