我刚刚开始学习在 Rails 中使用 rspec 进行测试。我有一个用户模型,我正在尝试编写一个测试来让用户登录。以下工作:
describe "user login" do
let(:user) { FactoryGirl.create(:user) }
it "logs user in" do
visit root_path
click_link "Log In"
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Submit"
expect(page).to have_content("You are now logged in.")
end
end
在我的application_controller.rb
我有以下方法:
def sign_in(user)
cookies.permanent[:auth_token] = user.auth_token
current_user = user
end
helper_method: sign_in
我想知道为什么我的sign_in
方法在以下测试中不起作用:
describe "user login2" do
let(:user) { FactoryGirl.create(:user) }
it "logs user in" do
sign_in(user)
expect(page).to have_content("You are now logged in.")
end
end
我收到以下错误:Failure/Error: sign_in(user)
NoMethodError:
undefined method 'sign_in'