0
我剛剛開始學習使用rspec在Rails中進行測試。 我有一個用戶模式,我試圖寫一個測試,以登錄用戶的以下工作:sign_in user test 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
我「M想知道爲什麼我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'