Sha256: 5de85a794a6cf2c164bb6389dd6884a484f55b44c73abb007d81622a321d8885

Contents?: true

Size: 1.27 KB

Versions: 22

Compression:

Stored size: 1.27 KB

Contents

# coding: UTF-8


# Steps to travel through time using [Timecop](https://github.com/jtrupiano/timecop).
# 
# See [this article](https://makandracards.com/makandra/1222-useful-cucumber-steps-to-travel-through-time-with-timecop) for details.


if defined?(Timecop)

  # Example:
  #
  #       Given the date is 2012-02-10
  #       Given the time is 2012-02-10 13:40
  When /^the (?:date|time) is "?(\d{4}-\d{2}-\d{2}(?: \d{1,2}:\d{2})?)"?$/ do |time|
    Timecop.travel(Time.zone ? Time.zone.parse(time) : Time.parse(time))
  end

  # Example:
  #
  #       Given the time is 13:40
  When /^the time is "?(\d{1,2}:\d{2})"?$/ do |time|
    Timecop.travel(Time.zone ? Time.zone.parse(time) : Time.parse(time)) # date will be today
  end

  # Example:
  #
  #       When it is 10 minutes later
  #       When it is a few hours earlier
  When /^it is (\d+|a|some|a few) (seconds?|minutes?|hours?|days?|weeks?|months?|years?) (later|earlier)$/ do |amount, unit, direction|
    amount = case amount
               when 'a'
                 1
               when 'some', 'a few'
                 10
               else
                 amount.to_i
             end
    amount = -amount if direction == 'earlier'
    Timecop.travel(Time.current + amount.send(unit))
  end

  After do
    Timecop.return
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
spreewald-0.6.5 lib/spreewald/timecop_steps.rb
spreewald-0.6.4 lib/spreewald/timecop_steps.rb
spreewald-0.6.3 lib/spreewald/timecop_steps.rb
spreewald-0.6.2 lib/spreewald/timecop_steps.rb
spreewald-0.6.1 lib/spreewald/timecop_steps.rb
spreewald-0.6.0 lib/spreewald/timecop_steps.rb
spreewald-0.5.20 lib/spreewald/timecop_steps.rb
spreewald-0.5.19 lib/spreewald/timecop_steps.rb
spreewald-0.5.18 lib/spreewald/timecop_steps.rb
spreewald-0.5.17 lib/spreewald/timecop_steps.rb
spreewald-0.5.16 lib/spreewald/timecop_steps.rb
spreewald-0.5.15 lib/spreewald/timecop_steps.rb
spreewald-0.5.14 lib/spreewald/timecop_steps.rb
spreewald-0.5.13 lib/spreewald/timecop_steps.rb
spreewald-0.5.12 lib/spreewald/timecop_steps.rb
spreewald-0.5.11 lib/spreewald/timecop_steps.rb
spreewald-0.5.10 lib/spreewald/timecop_steps.rb
spreewald-0.5.9 lib/spreewald/timecop_steps.rb
spreewald-0.5.8 lib/spreewald/timecop_steps.rb
spreewald-0.5.7 lib/spreewald/timecop_steps.rb