私はRailsの初心者です。FactoryGirl を使用して統合テスト用のユーザーを作成していますが、テストでユーザーをサインインする方法がわかりません。
私の工場は次のようになります。
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}@ticketee.com" }
password "password"
password_confirmation "password"
end
factory :confirmed_user do
after_create { |user| user.confirm! }
end
end
そして、私のテストは次のようになります。
feature 'Editing an exercise' do
before do
ex = FactoryGirl.create(:ex)
user = FactoryGirl.create(:user)
user.confirm!
sign_in_as!(user)
end
scenario 'can edit an exercise' do
visit '/'
click_link 'Exercises'
click_link 'running'
click_link 'edit'
fill_in 'Name', :with => 'kick boxing'
fill_in 'Description', :with => 'kicking a box'
click_button 'Save'
page.should have_content('Exercise updated!')
page.should have_content('kick boxing')
end
end
テストを実行すると、次のエラーが表示されます。
Failure/Error: sign_in_as!(user)
NoMethodError:
undefined method `sign_in_as!'
for #<RSpec::Core::ExampleGroup::Nested_1:0xb515ecc>
アプリはうまく機能します。失敗するのはテストだけです。どんな助けでも大歓迎です。ありがとう!