Ruby on rails 在rails中使用cucumber和capybara单击链接/按钮后,如何遵循重定向?
我目前正在尝试为一个新的rails 3应用程序与cucumber和capybara进行集成/验收测试。(我最初计划使用webrat,但它似乎不支持rails 3,所以我最终使用了capybara) 我正在尝试进行基本的登录测试:Ruby on rails 在rails中使用cucumber和capybara单击链接/按钮后,如何遵循重定向?,ruby-on-rails,redirect,cucumber,capybara,Ruby On Rails,Redirect,Cucumber,Capybara,我目前正在尝试为一个新的rails 3应用程序与cucumber和capybara进行集成/验收测试。(我最初计划使用webrat,但它似乎不支持rails 3,所以我最终使用了capybara) 我正在尝试进行基本的登录测试: Feature: Login user In order to access the non-public parts of the site, as a user, I want to login to the site Scenario: login
Feature: Login user
In order to access the non-public parts of the site,
as a user,
I want to login to the site
Scenario: login with valid credentials
Given I am on the login page
When I fill in "Email" with "bender@planetexpress.com"
And I fill in "Password" with "pass"
And I press "Login"
Then I should be on the users home page
And I should see "Login successful"
现在的问题是,登录表单将我发送到/user\u session
,然后将我重定向到用户主页/home
。Cucumber没有遵循重定向,这会导致然后我应该在用户主页上的
行失败
我怎样才能告诉cucumber/capybara跟随重定向,以便在我点击follow a link(跟随链接)按钮后,我在正确的页面上
似乎有一个follow\u重定向我正在使用的rack_测试驱动程序中的code>方法,但它是私有的,我不知道如何调用该功能
提前感谢,
Simon可能有效的方法是切换语句的顺序:
Then I should see "Login successful"
And I should be on the users home page
然后,将在检查页面文本之后检查当前页面。Cucumber测试确实需要大量调试,祝你好运 水豚会自动跟随重定向。其他东西坏了。将此添加到您的步骤中:
When /^I dump.* the response$/ do
puts body
end
然后,当您的测试出现问题时,您可以在步骤中添加“并且我转储响应”,然后查看重定向或其他方面的结果。这是我最担心的答案,但我也从另一个来源听到了这一点。需要调查一下…哦!我的测试数据有问题。难怪如果数据库中不存在用户,它就不能工作。谢谢你的帮助!水豚跟随重定向。机架::只有在调用follow\u redirect时,测试才会跟随redirect代码>:我对此投了反对票,因为机架测试不会自动跟随重定向,这里有一条评论说,但答案尚未更新。