2011-03-28 100 views
2

我正在試圖用黃瓜爲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 = '[email protected]' 
    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) 

我不知道爲什麼發生這種情況,任何想法?

+0

請包括您的控制器代碼的登錄帖子操作以及任何相關的之前和之後的過濾器。 – 2011-03-28 15:20:48

+0

你能張貼你的路線嗎?你指定了一個根? – carols10cents 2011-03-30 21:53:04

回答

0

可能是大量的東西 - 沒有辦法告訴沒有更多的代碼。一些可能性:

  • 您是否要求登錄頁面的身份驗證?這可以讓你在一個循環。要排除從您的身份驗證解決方案
  • 「打開」網頁(例如sign_in)你可以把當時給我看網頁需要更高的,所以你可以看到究竟發生了什麼
  • 你可以重置回的默認值您的身份驗證解決方案(例如,設計)通過評論其他路線只是爲了看看發生了什麼

當您通過瀏覽器嘗試時會發生什麼?

+0

我遇到了在瀏覽器中運行但在測試中不能運行的問題。我最終看着'log/test.log',在那裏我可以看到重定向到了哪裏。這幫助我找到了問題的根源。 (它是由我的開發數據庫中存在的一些東西觸發的,但不是在測試數據庫中) – amoebe 2013-09-25 17:02:19