The vast majority of my cucumber features require the user to be logged in. However I don't really need to test the login functionality for every single test. I'm currently using Devise for my authentication.
I'm looking for a way to sign a user in with devise, without filling out the sign in form. Is there anyway to do this? I would prefer to not have to use the sign in action for every test.
No, there is no way. In the documentation, with regard to the
sign_in @user
andsign_out @user
helper methods, it says:As you said yourself, it is probably cleanest to do it with a
before :each
block. I like to structure it like the following:I found this to be quite useful, since if I change authentication rules (i.e. whether or not the user has to be logged in for a specific path) I can just take the whole test and move it into the other description block, without changing any more code.
Generally, you should always test through the interface. But I think this is an acceptable exception.
I'm using devise with capybara with rspec but it should work for you too.
In a helper I have this:
Then in the feature:
Also see:
How to Stub out Warden/Devise with Rspec in Capybara test