7

我目前正在尝试为带有黄瓜和水豚的新 Rails 3 应用程序设置集成/验收测试。(我本来打算用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 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_session该表单,然后将我重定向到用户 home /home。Cucumber 不遵循导致Then I should be on the users home page线路失败的重定向。

我如何告诉 cucumber/capybara 跟随重定向,以便在我点击跟随链接按钮后我在正确的页面上?

我正在使用的 rack_test 驱动程序中似乎有一个follow_redirect!方法,但它是私有的,我不知道如何调用该功能。

提前谢谢,
西蒙

4

3 回答 3

14

Capybara 自动跟随重定向。别的东西坏了。

于 2010-07-25T17:37:42.153 回答
6

将此添加到您的步骤中:

When /^I dump.* the response$/ do
  puts body
end

然后,当您的测试行为不端时,您可以将“我转储响应”添加到您的步骤中,并查看重定向或其他内容的去向。

于 2010-12-05T20:04:24.963 回答
1

可能有用的是切换语句的顺序:

Then I should see "Login successful"
And I should be on the users home page

然后在检查页面文本之后检查当前页面。Cucumber 测试确实需要大量调试,祝你好运!

于 2010-07-23T18:54:08.350 回答