-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Devise with Rails 8 and Rspec does not load strategies when run single test #5771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same problem here. I have the identical configuration:
|
I believe I have some insight, rough though it may be. I just ran into a similar pattern today (single spec failing, but not as a suite) and have been a few hours trying to make sense of it. In my particular scenario, the problem looks to be coming from devise's controller helpers being set up before rails routes are drawn. In my RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
end and if you look at that helpers code, there is some setup there. One of the methods called is What works for me, for now, is RSpec.configure do |config|
config.before(:suite) do
Devise.configure_warden!
end
end Update: I wrote before fully reading the linked thread and I see there's a similar approach and conclusion. Though I do find my approach to be more concise and focused to the problem at hand. |
Thanks; the For reference, for me the error only manifested locally (not CI), and in the first test. The exception (locally) when running The repo is public in case helpful for reproduction - landgrab/landgrab#580
|
Hmm, the solutions does not work for us . |
While I can peck my way around, I lack fluency in devise. I went back to where I had implemented the solution that worked for me, and tried to understand exactly what you're experiencing, @Piioo, but was unlucky. While I had experienced this in controller specs, I was able to reproduce in request specs. Given I have little context of your scenario, it's hard to assume that I can grasp what's going on in your app, but to get as close as possible I dropped in the example code you posted (tweaked it for some observability), and configured it as such so that it's sure to be the first strategy tried Devise.setup do |config|
config.warden do |manager|
manager.default_strategies(scope: :user).unshift :cookie_auth
end
end Given you didn't share any additional implementation details, it's only for me to guess as to how your specific scenario is set up. Here's my example, simplified. it "confirms the sign in workflow" do
user = create(:user)
post "/sign-in", params: { user: { email: user.email, password: "temp12345678" } }
expect(response.status).to eq(303)
end This fails without the fix I implemented
but when I drop Now in the above example, there's an additional step I left out during testing that was causing the example to pass without the addition of it "confirms the sign in workflow" do
user = create(:user)
get "/account" # the additional step
post response.location, params: { user: { email: user.email, password: "temp12345678" } }
expect(response.status).to eq(303)
end If adding something similar to your failing example causes it to pass, that could provide some additional clues into what is causing the problem. Hope that provides, at the least, a tiniest grain of insight. |
I don't think this problem is limited to tests. I am seeing this in a production 8.0.2 app. See #5774 |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm not sure if I'm in the right place, I have a problem with devise strategies and rspec after Rails update to version 8.0.1.
We have a custom strategy which we load into the devise strategies (see below) and it does work fine on development/production and test when I run all test from one file at once. The strategies are all loaded in the
manager
and are found inproxy.rb
to run the correctauthenticate!
in our custom strategy.When I run a specific test like
rspec spec/requests/foo/create_spec.rb:123
, then themanager
default_strategies are always empty and the test stops at the authentication.I have seen others have similar problems when running one test: #5752 (comment)
Has someone an Idea?
devise (4.9.4)
rails (8.0.1) (with 8.0.2 it's not better)
rspec-core (3.13.3)
rspec-rails (7.1.1)
The text was updated successfully, but these errors were encountered: