Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View temporal_cucumber_helpers.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
require 'chronic'
require 'timecop'
 
module TemporalHelpers
# Travels to +time+ and lets the clock keep running.
#
# If a block is given, executes the block at that
# time then returns to the present.
def travel_to(time, &block)
Timecop.travel parse_time(time), &block
end
# Travels to and freezes the clock at +time+.
#
# If a block is given, executes the block at that
# time then returns to the present.
def freeze_time_at(time, &block)
Timecop.freeze parse_time(time), &block
end
private
def parse_time(time)
Chronic.parse(time) || Time.parse(time)
end
end
 
World(TemporalHelpers)
 
Given /^it is currently (.+)$/ do |time|
travel_to time
end
 
Given /^time is frozen at (.+)$/ do |time|
freeze_time_at time
end
 
Given /^(?:I|we) jump in our Delorean and return to the present$/ do
Timecop.return
end
 
After do
Timecop.return
end

nice, thanks for this one!

Cool thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.