For nearly every integration test, a user has to be signed into Devise. This takes a lot of time, so I wondered whether there’s a way to set up the user session without having to visit the login page, enter details, and press the login button.
Maybe there’s a helper method built into Devise that immediately signs a given user in?
Thanks a lot for help.
In the header of your spec file, insert
include Warden::Test::HelpersandWarden.test_mode!, like this:In above code, i used FactoryGirl to create an user. You can use other ways you like to create user. Then I login
userby using methodlogin_as. Then you can run any test and you can sureuserhas loged in. I think this is what you want, hope this help. You can see more details here Test with capybara.EDIT
To make sure this works correctly you will need to reset warden after each test you can do this by calling
If for some reason you need to log out a logged in test user, you can use Warden’s logout helper.