HasPhoneNumber

with_time_frozen at is a testing helper that makes time-sensitive testing easy!

How, you ask?

class TimeSensitiveTest < Test::Unit::TestCase
  def test_that_something_happens_at_this_exact_time
    expected_time = Time.local(1984, 5, 15)

    with_time_frozen_at expected_time do |time|
      assert_equal expected_time, Time.now
      assert_equal expected_time, time
    end
  end
end

Inside the block you pass to with_time_frozen_at, Time.now returns the time that you specified in the call. This time is also passed as a block argument for your convenience.

Credits

This version of with_time_frozen_at was inspired by the variant that was written by the authors in 2008. That implementation may have been slightly different and depended on Rails. This one does not.