我是 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>
该应用程序运行良好,只是测试失败。任何帮助,将不胜感激。谢谢!