2014-10-28 51 views
1

我正在開發一個rails應用程序,我遵循Michael Hartl着名的教程。我正在使用更新版本的RSpec和水豚,因此遇到了問題。由於水豚2,您需要place tests using Capybara in spec/features。 RSpec Capybara does no longer請求規格。 Hartl給出的解決方案因此不再有效(他將所有測試都放在規範/要求中)。在請求規範中登錄沒有水豚的用戶

我需要在請求測試中登錄沒有水豚的用戶(因爲測試使用了「put」,它只能在請求規格中使用)。同樣的問題其他人似乎與已經解決了這個問題:

post login_path(session: { password: user.password, email: user.email }) 
cookies[:remember_token] = user.remember_token 

,但我得到的錯誤:

Failure/Error: before { valid_login_request(user) } 
NoMethodError: 
    undefined method `[]' for nil:NilClass 
# ./app/controllers/sessions_controller.rb:7:in `create' 
# ./spec/support/utilities.rb:13:in `valid_login_request' 
# ./spec/requests/authentication_pages_spec.rb:22:in `block (4 levels) in <top (required)>' 

和sessions_controller.rb:7是下面的代碼:

user = User.find_by_email(params[:session][:email]) 

經過一番研究後,我發現這是一個零的會話,這就是爲什麼我得到上面的「NoMethodError」。我該如何解決這個問題?

回答

0

我解決了它。我轉向Hartl的新指南,並在那裏找到了一種授權用戶使用臨時和永久Cookie的方法。