After looking at somebody else's code I have noticed the following:
login_as user, scope: :user
I have always used simply
login_as user
So I went out to look for an explanation and found this article How to: Test with Capybara that says use scope: :user
however without any explanation. All my tests are working fine without it.
Another strange thing is Warden.test_mode!
which I am not using either. Why would I need it?
Any explanation?
1.
As you can see here,
login_as
callsset_user
with the same set of options.Here's the source code of
set_user
(click "View source"). On line 165, you'll see that if the:scope
option is empty, the default scope will be used. In your Rails application, openconfig/initializers/devise.rb
, you'll find something as followsIt means your default scope is
:user
which is used when you calllogin_as
without passing a scope.2.
Here's the documentation of
Warden.test_mode!
It means if you're sure you won't need/use any of the helper methods provided by warden as listed, not calling this method won't break your tests.