Rails 3 with Devise and rspec: Warden Test Assistants Unreliable

I have an application using rails 3.2 and Devise. I have a test query set using rspec and Capybara.

I tried switching to using the Warden Test Assistants in my sign in the helper, instead of Capybara filling out the login form and submitting it. Due to the size and complexity of my test suite, this results in a half time savings on my test time.

In my configuration there are:

RSpec.configure do |config| config.include Warden::Test::Helpers, :type => :request config.after :each do Warden.test_reset! end end 

And in the context of:

 let!(:current_user) { FactoryGirl.create(:user) } background do login_as(current_user, :scope => :user) end 

However, when starting a test suite using these configurations, almost every test run has a different random query response with an error due to a page that appears as if the user was not logged in. (In particular, links controlled by the conditional expression user_signed_in? ),

My question is: Has anyone else encountered such insecurity and how can it be mitigated?

+7
source share
2 answers

It’s absolutely easiest to use the sign_in form in your before :each block. You need test assistants in Controller specifications because they are isolated from development. You do not have this problem in the integration test.

+1
source

Although an old post, I also have this problem with Rails 4.1 and Warden 1.2.3. I noticed that there is a new version of Warden with work on test assistants. Any success with the newer version?

The behavior that I observe is that Warden is not always successfully registered through the login_as helper. This leads to the fact that my application appears on the login page instead of the place that, in his opinion, should be.

0
source

All Articles