No, there is no way. The documentation for helper methods sign_in @user and sign_out @user says:
These assistants are not going to work on the integration tests conducted by Capybara or Webrat. They are intended for use with functional tests only. Instead, fill out the form or explicitly set the user in a session
As you said yourself, this is perhaps the cleanest way to do this using the before :each block. I like to structure it as follows:
context "login necessary" do # Before block before do visit new_user_session_path fill_in "Email", with: " test@test.com " fill_in "Password", with: "password" click_button "Login" assert_contain "You logged in successfully." end # Actual tests that require the user to be logged in it "does everything correctly" do # ... end end context "login not necessary" do it "does stuff" do # code end end
I found this to be very useful, because if I change the authentication rules (that is, whether the user should be registered for a certain path), I can just take the whole test and transfer it to another description block, without changing the code.
source share