brad
brad

Reputation: 9773

Is there a way of testing for cookie expiry in cucumber tests?

I want to set a 'remember me' cookie on my website with a 2 week expiry rather than permanent and want to test for this.

My attempt at this has so far been unsuccessful.

Here's my cucumber scenario;

Scenario: A user logs in with the remember me checkbox ticked and then remains inactive for more than 2 weeks
    Given I am a registered user
    When I log in with the remember me checkbox ticked
    And more than 2 weeks passes
    And I visit the dashboard page
    Then I should be logged out

My step definition for the 3rd step (the one that matters) is as follows

When /^more than (\d+) weeks passes with no activity$/ do |num|
  Timecop.freeze(Time.now + num.to_i.weeks + 1.day)
end

Doing a similar test for session expiry for a user without 'remember me' works just fine but this depends on a last_request_at column in my user table. This test depends on the browser (in this case Capybara) expiring my auth_token cookie. Is there a way of doing this test?

Upvotes: 2

Views: 247

Answers (0)

Related Questions