リクエストの仕様を機能させようとして立ち往生しています。Google と SO で見つけたさまざまなアプローチをいくつか試しました。以下は、リクエスト仕様で個別に試した次のヘルパーです。
#spec/support/devise_request_spec_support.rb
module DeviseRequestSpecSupport
def login(user)
post user_session_path, login: user.email, password: 'foobar'
end
end
#spec/support/utilities.rb
include ApplicationHelper
def valid_login(user)
fill_in "user[email]", with: user.email
fill_in "user[password]", with: 'foobar'
click_button "Sign in"
end
def login(user)
visit root_path
valid_login(user)
end
#login
以下のリクエスト仕様で、上記の両方の方法を別々に試しました。
require 'spec_helper'
describe "Company Admin Dashboard", js: true do
let(:user) { Fabricate(:company_admin) }
before do
login(user)
poll = Fabricate(:poll)
poll.send_to_all_users
end
describe "interacting with the poll box" do
it "displays sent poll in poll box" do
visit root_path
end
end
end
テストはパスしますが、root_path にはログイン ユーザー向けのランディング ページが表示されません。パブリック ランディング ページが表示されます。binding.pry を使用してデバッグを試み、テスト環境で手動でログインしようとしましたが、「無効な電子メールまたはパスワード」エラーが発生し続けます。何度も確認しましたが、偽造された company_admin の正しいメールアドレスとパスワードを使用しています。
ここで提案されているソリューションも試しました: https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
どんな助けでも大歓迎です。問題がどこにあるのかわかりません。ファブリケーション ジェム、Devise、RSpec、またはカピバラですか?