Rails 3 with Devise and rspec: Warden test helpers unreliable
Asked Answered
D

2

7

I have an application using rails 3.2 and Devise. I have a request test suite using rspec and Capybara.

I have attempted to shift to using the Warden test helpers in my sign in helper rather than having Capybara fill in the sign in form and submit it. Due to the size and complexity of my test suite, this results in over a minute and a half of savings in my test runtimes.

In my configuration is:

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

And in a Context:

let!(:current_user) { FactoryGirl.create(:user) }

background do
  login_as(current_user, :scope => :user)
end

However, when running the test suite using these configurations nearly every test run has a different randomly failing request spec due to the page presenting as though the user were not logged in. (Specifically, links controlled by a user_signed_in? conditional)

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

Dopey answered 11/6, 2012 at 20:58 Comment(0)
P
1

The absolute easiest thing to do is just use the sign_in form in your before :each block. You need the test helpers in Controller specs, because it's isolated from devise. You don't have that problem in an integration test.

Paraffinic answered 12/6, 2012 at 3:6 Comment(3)
I agree that is the easiest and that is the solution I am using for now. However, I really want that minute and a half cut off my tests.Dopey
have you tried just posting the email/password to user_session_path?Paraffinic
Yes, that works fine with selenium, but due to some issues with selenium and firefox we are using capybara-webkit which does not support posting data to a URL directly.Dopey
K
0

Though an old post I also have this problem with Rails 4.1 and Warden 1.2.3. I noticed that there is a newer version of Warden with work on the test helpers. Anyone success with the newer version?

Btw the behavior that I observe is that Warden does not always successfully login via the login_as helper. This results in my app finding itself on the login page instead of the place it thought it ought to be.

Keaton answered 4/5, 2016 at 16:11 Comment(1)
I'm using Rails 4.1.16 with Warden 1.2.6 and no luck here.Steatite

© 2022 - 2024 — McMap. All rights reserved.