簡體   English   中英

rspec + capybara rails 4-rake集成測試失敗

[英]rspec + capybara rails 4 - rake integration testing fails

我正在嘗試測試設計登錄,注銷和所有其他方案,但是我無法過去一個方案,請讓登錄失敗

在我的特征中

scenario 'user cannot sign in if not registered' do
   login_as('user2@example.com', 'meow')
   visit overviews_path
   save_and_open_page
    expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
end

我也有sign_in幫助程序設置為;

 def sign_in(email, password)
  user.confirm!
  visit new_user_session_path
  fill_in 'Email', with: email
  fill_in 'password', with: password
  click_button 'Log in'
end

但是,這會導致錯誤;

expected to find text "Invalid email or password." in "TypeError at /overviews ======================= > no implicit conversion of Symbol into Integer spec/features/users/sign_in_spec.rb, line 14

有任何想法嗎?

您已將助手方法命名為sign_in但在您的方案中正在調用login_as 您應該使用一種方法或另一種方法,不能同時使用兩種方法。

更新:好的,重新檢查文檔 ,並且您應該使用自己的幫助程序來模擬實際的用戶登錄,或者使用login_as提供的login_as ,在這種情況下,請確保login_as其包含在測試/ rspec中設定:

include Warden::Test::Helpers
Warden.test_mode!

附帶說明一下,您應該在工廠/夾具中確認用戶,而不是在helper方法(可能未定義)中確認用戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM