我想在我的网站上设置一个“记住我”的 cookie,有效期为 2 周而不是永久,并想对此进行测试。
到目前为止,我在这方面的尝试没有成功。
这是我的黄瓜场景;
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
我对第三步(重要的一步)的步骤定义如下
When /^more than (\d+) weeks passes with no activity$/ do |num|
Timecop.freeze(Time.now + num.to_i.weeks + 1.day)
end
为没有“记住我”的用户进行类似的会话到期测试工作得很好,但这取决于我的用户表中的 last_request_at 列。此测试取决于浏览器(在本例中为 Capybara)使我的 auth_token cookie 过期。有没有办法做这个测试?