timecop
timecop copied to clipboard
Timecop doesn't persist over simulated page loads in Cucumber tests
I just ran into a problem where I'm using Timecop in a cucumber feature so that I can drop specific dates into my scenarios without having to worry about when I run the feature:
Background:
Given it is now "March 2 2011"
Scenario: Admin user creates an event
Given I am logged in as a user (admin)
When I am on the home page
And I follow "Add event"
And I fill in the following:
| event_timestamp_1i | 2011 |
| event_timestamp_2i | March |
| event_timestamp_3i | 9 |
| event_description | The first event |
And I press "Create Event"
Then I should have 1 future event
And I should see "March 9th, 2011" within "#next_event"
However the scenario fails. It seems from experimentation that - after the page load from "Create Event" - the time is reset to the real Time.now
and the "future" event is now in the past.
Is there a way around this?
It's surprising that I have not encountered this yet. The problem as you describe sounds reasonable (I have not repro'd but it makes sense). I don't have any immediate recommendations. I'll have to play around with it. Luckily I'll be writing some time-specific cuke scenarios in the next day or two. I'll follow up if I come up with a solution.
In the meantime you can just put another "Given it is now" step in there and move along.
I confirm this problem. moving to other page reset the time