Posted over 10 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 Archive steps:

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:

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:

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.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Ulrich Berkmueller
Last edit:
over 3 years 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 short-lived cookies to improve usability.
Accept or learn more