In the header of your spec file, insert include Warden::Test::Helpers
and Warden.test_mode!
, like this:
require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!
describe "AuthenticationPages" do
let(:user) { FactoryGirl.create(:user) }
before { login_as(user, scope: :user }
...
In above code, i used FactoryGirl to create an user. You can use other ways you like to create user. Then I login user
by using method login_as
. Then you can run any test and you can sure user
has 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
Warden.test_reset!
If for some reason you need to log out a logged in test user, you can use Warden's logout helper.
logout(:user)