ruby on rails - TimeWithZone & Time.zone.now integration test fails -
in controller method set user's variable activation_sent_at
equal time.zone.now
when activation email sent user. on development server seems work (although time expressions in application 2 hours behind on local time of computer).
i want include integration test tests whether activation_sent_at
indeed gets set properly. included line:
assert_equal @user.activation_sent_at, time.zone.now
however, produces error:
no visible difference in activesupport::timewithzone#inspect output. should @ implementation of #== on activesupport::timewithzone or members.
i think it's suggesting use expression time.zone.now
in test. i've looked @ different sources, including http://api.rubyonrails.org/classes/activesupport/timewithzone.html, not sure here. suggestions causing error?
additional info: adding puts time.zone.now
, puts @stakeholder.activation_sent_at
confirms 2 equal. not sure generates failure/error.
the issue 2 dates close each other not same. can use assert_in_delta
assert_in_delta @user.activation_sent_at, time.zone.now, 1.second
for rspec, similar approach use be_within
:
expect(@user.activation_sent_at).to be_within(1.second).of time.zone.now
Comments
Post a Comment