Flowdock
method

travel

Importance_2
v4.2.7 - Show latest stable - 0 notes - Class: TimeHelpers
travel(duration, &block) public

Changes current time to the time in the future or in the past by a given time difference by stubbing Time.now and Date.today.

Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
travel 1.day
Time.current # => Sun, 10 Nov 2013 15:34:49 EST -05:00
Date.current # => Sun, 10 Nov 2013

This method also accepts a block, which will return the current time back to its original state at the end of the block:

Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
travel 1.day do
  User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00
end
Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
Show source
Register or log in to add new notes.