Please understand that I cannot speak English well. I'm having trouble with the rails rspec error not being resolved. Rails web app login integration test error. I'll attach the error and test details here.
I designed the controller's create method to "redirect to home after login". create method for "login and redirect to home" And it has been confirmed that it returns to home after logging in on the development server. But it doesn't work in integration tests. I wondered why. Perhaps the user data prepared for testing is not loaded properly? so i can't redirect to home after login? Factory bot gems and user data generation files required to create RSpec test user data gem for tests As an aside, this is my first time writing integration tests in RSpec. So there may be some rookie mistakes. Thank you very much.
FactoryBot.build(:user)
initializes a user in memory, but doesn't save it into the database. That means the login fails, because a user with that email is not found in the database. And because the login failed, the user is still on /login
.
To fix this, just change
before do
@user = FactoryBot.build(:user)
end
to
before do
@user = FactoryBot.create(:user)
end
in your user_login_spec.rb
.