Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Leif Bladt's Profile

GitHub User: leifbladt


Comments by Leif Bladt


You're right. The Timecop version is more deterministic and that is what our tests should be.

But there maybe situations where you can't use Timecop and you don't need to test on milliseconds (with an increased delta to get a more robust test), then it might be a good solution too.


Testing with times involved is mostly no fun, particularly because I never heard of Timecop before :) But I found a way to manage it with RSpec matchers:

it "saves the time the password reset was sent" do
  user.reload.password_reset_sent_at.should be_within(1.second).of(