2013-06-03 260 views
0

每次我運行默認的設計user_step測試「登錄」它失敗。黃瓜設計登錄步驟失敗(導軌3.2,黃瓜,水豚,rspec)

奇怪的是錯誤我得到

Scenario: User signs in successfully  # features/users/sign_in.feature:12 
    Given I exist as a user    # features/step_definitions/user_steps.rb:58 
    And I am not logged in     # features/step_definitions/user_steps.rb:49 
    When I sign in with valid credentials # features/step_definitions/user_steps.rb:72 
    Then show me the page     # features/step_definitions/user_steps.rb:152 
And I see a successful sign in message # features/step_definitions/user_steps.rb:156 
     expected to find text "Signed in successfully." in "Mywebsite Follow us How it works More Login × **Invalid email or password**. Login * Email Password Remember me Not a member yet? Sign Up Now!Forgot your password?Didn't receive confirmation instructions? Rails Tutorial " (RSpec::Expectations::ExpectationNotMetError) 
     ./features/step_definitions/user_steps.rb:157:in `/^I see a successful sign in message$/' 
     features/users/sign_in.feature:17:in `And I see a successful sign in message' 

正如你看到的水豚/黃瓜嘗試連接,但得到「無效的電子郵件或密碼

所以我用看到SO和竅門添加看什麼水豚真的越來越

Then /^show me the page$/ do 
    save_and_open_page 
end 

它試圖使用我放在我的文件頂部user_ste ps.rb:

def create_visitor 
    @visitor ||= { :name => "Testy McUserton", :email => "[email protected]", 
    :password => "please", :password_confirmation => "please" } 
end 

但它可以讓我「無效的(我可以看到[email protected]寫在capyabra頁上的電子郵件字段,以便其瞭解,我想這是電子郵件。

我迷路了。爲什麼它不起作用?

回答

0

您需要先在數據庫中創建用戶。 User.create(name: "Testy McUserton", email: "[email protected]", password: "please", :password_confirmation: "please")。然後你可以用憑證登錄。您也可以使用factorygirl link