Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/time_warp.rb

Instance Method Summary collapse

Instance Method Details

#pretend_now_is(*args) ⇒ Object

Time warp to the specified time for the duration of the passed block.



9
10
11
12
13
14
15
16
17
18
# File 'lib/time_warp.rb', line 9

def pretend_now_is(*args)
  Time.testing_offset = Time.now - time_from(*args)
  if block_given?
    begin
      yield
    ensure
      reset_to_real_time
    end
  end
end

#reset_to_real_timeObject

Reset to real time.



22
23
24
# File 'lib/time_warp.rb', line 22

def reset_to_real_time
  Time.testing_offset = 0
end