Posted over 8 years ago. Visible to the public.

Cucumber steps to travel through time with Timecop

These steps are now part of Spreewald.


Here are some useful examples how to use the attached Cucumber Timecop steps:

Copy
When the date is 2011-05-06 When the time is 2011-05-06 17:30

There is also one really awesome step that lets you travel to the past or to the future:

Copy
When /^it is (\d+|a|some) (seconds?|minutes?|hours?|days?|months?|years?) (later|earlier)$/

As you can see, you describe the time unit amount in 3 different ways:

  • a number, e.g. 5
  • the word a
  • the word some

Then you can describe the time unit itself. May it be seconds, minutes, …, or years.

Last but not least you can define the time travel direction. Would you like to have a look at the past, use the word "earlier", otherwise use the word "later" to travel to the future. (Note: Please give me some good stock advice or tell me the lottery numbers when you come back ;-))

For example, you can use the step above like that:

Copy
Given it is some years later When I have analyzed the stock market And it is some years earlier Then I should give some stock advice to the author of this note

Note that this will not mock the time in a Selenium-controlled browser window. Use timemachine.js for that.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Ulrich Berkmueller
Last edit:
over 1 year ago
by Thomas Eisenbarth
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Ulrich Berkmueller to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more