2010-08-12 29 views
7

我想要一个黄瓜功能测试devise的可记忆功能(记住我的cookie)。如何使用Cucumber来测试Devise的Rememberable功能?

使用水豚很容易检查记住我的复选框,但我应该如何模拟用户在关闭窗口后返回网站?

+0

为什么你要当色器件本身会做到这一点的除了有测试? – 2010-08-12 18:38:45

+1

因为我认为确保我在集成级别测试此功能非常重要 - 即 - 我是否正确使用它?,它工作正常吗?并且我的客户可以看到它在基于黄瓜的情况下正常工作验收测试? – srboisvert 2010-08-15 11:01:24

回答

1

我想出了下面的机架测试黑客和稍微更清洁的硒api使用,以测试黄瓜/水豚设计记忆我的功能。它只是告诉驱动程序手动清除会话cookie。并不是所有的设备都支持,我只实现我用两个:

http://gist.github.com/484787

这是假设会话删除Cookie存储。从场景中删除@announce标签以消除冗长。

另一种选择,在the mailing list discussion由马特·怀恩建议,可寻找其他的饼干店,并通过查询或文件删除删除它们:

从敏捷轨书举:

config.action_controller.session_store = CGI::Session::PStore (or just :p_store) 
config.action_controller.session_options[:tmpdir] = "/Users/dave/tmp" 
config.action_controller.session_options[:prefix] = "myapp_session_" 

rake db:sessions:create 
config.action_controller.session_store = :active_record_store 

Rails也有一个重置会话方法,但我相信我们无法访问它,因为我们无法在测试时挂入rails会话与水豚。

希望这有助于

尼克

0

我用email-spec来完成这个。我的情况如下所示:

@allow-rescue 
Scenario: Create New Account (Everything cool) 
Given I am not authenticated 
When I go to register 
And I fill in "Name" with "bill" 
And I fill in "Email" with "[email protected]" 
And I fill in "Password" with "please" 
And I fill in "Password Confirmation" with "please" 
And I press "Sign up" 
Then "[email protected]" should receive an email 
And I open the email 
And I should see "Confirm my account" in the email body 
When I follow "Confirm my account" in the email 
Then I should see "Your account was successfully confirmed. You are now signed in." 

注意@允许救援装饰使用设计时需要上述情形。

希望这会有所帮助。

+0

这很方便,特别是电子邮件规范,但是我想了解有关测试Devise可记忆功能的知识 - 这就是cookie存储功能,因此用户每次访问该网站时都不需要不断登录。 – srboisvert 2010-08-15 11:00:38

0

我想你可以注销与水豚,然后重新登录类似

Given I am on the login screen 
And I select 'Remember Me' 
And I click 'login' 
Then I should be 'logged in' 
When I click 'log out' 
Then I should be 'logged out' #=> potentially destroy a session here? 
When I click log in 
Then I should be logged in 
And I should not be directed to the login form. 

应该使用cabybara当前的Cookie状态这一流程建模。

1

nruth的要点是真正有用的,但我觉得像删除由名称的Cookie是作弊。我创建了一个步骤,删除浏览器在关闭并重新启动时将删除的Cookie(任何未设置过期日期并设置过期日期的cookie)。

你可以在this commit中看到它(尽管我只是为RackTest驱动程序完成它,因为我没有安装Selenium)。您还可以在this commit中看到我的登录/ remember_me功能。我重构了这些类来分隔this commit中的文件。

我希望这很有帮助。

相关问题