Read more

Cucumber steps to travel through time with Timecop

Ulrich Berkmueller
May 23, 2011Software engineer

These steps are now part of Spreewald.


Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Here are some useful examples how to use the attached Cucumber Timecop Show archive.org snapshot 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.

Posted by Ulrich Berkmueller to makandra dev (2011-05-23 08:36)