Since Capybara runs in a different thread from the tests, session data is not available. So the Devise sign_in method does nothing for Capybara.
There are basically two solutions to get Capybara to authenticate:
- Use Capybara to login through a Devise login form by posting the user’s email and password
- Set session data in Capybara to simulate a login (basically do the same thing that Devise’s sign_in does)
For speed of tests reasons, I’d prefer to just set session data. After Googling around, I found this solution and modified it a bit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Now you just need to call create_logged_in_user and you’re good to go.
1 2 3 4 5 6 7 8