黄瓜和设计,重定向太多了?

时间:2011-03-28 12:25:05

标签: ruby-on-rails cucumber devise

我正在尝试用Devise为黄瓜创建一个测试。这是我的功能

Feature: Login to locomotive
  In order to login to locomotive
  As a user 
  I want to be able to use Locomotive

Scenario: Login to locomotive
    Given I am a authenticated user
    Then I should see "logged in as <email>"
    Then show me the page

这是我的用户步骤

Given /^I am not authenticated$/ do
  visit('/users/sign_out') # ensure that at least
end

Given /^I have one\s+user "([^\"]*)" with password "([^\"]*)" and username "([^\"]*)"$/ do |email, password, username|
  @user = User.new(:email => email,
           :username => username,
           :first_name => 'Josh',
           :last_name => 'Crowder',
           :password => password,
           :password_confirmation => password).save!
end

Given /^I am a authenticated user$/ do
  email = 'testing@man.net'
  username = 'josh'
  password = 'secretpass'

  Given %{I have one user "#{email}" with password "#{password}" and username "#{username}"}
  And %{I go to login}
  And %{I fill in "user_login" with "#{email}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

我收到此错误消息

F--

(::) failed steps (::)

redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)
./features/step_definitions/web_steps.rb:29:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:28:in `/^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/user_authentication.feature:7:in `Given I am a authenticated user'

Failing Scenarios:
cucumber features/user_authentication.feature:6 # Scenario: Login to locomotive

1 scenario (1 failed)
3 steps (1 failed, 2 skipped)

我不知道为什么会这样,有什么想法吗?

1 个答案:

答案 0 :(得分:0)

可能有很多东西 - 如果没有更多的代码,就无法分辨。一些可能性:

  • 您是否要求对登录页面进行身份验证?这可以让你陷入困境。您希望从身份验证解决方案中排除“打开”页面(例如sign_in)
  • 你可以把Then Show Me页面放得更高,这样你就可以看到完全正在发生什么
  • 您可以通过注释掉其他路线来重置回您的身份验证解决方案的默认设置(例如设计),以查看正在发生的事情

当您通过浏览器尝试时会发生什么?