Skip to content
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

be_successful on a request spec hangs #2592

Open
jcoyne opened this issue Apr 12, 2022 · 5 comments
Open

be_successful on a request spec hangs #2592

jcoyne opened this issue Apr 12, 2022 · 5 comments

Comments

@jcoyne
Copy link

jcoyne commented Apr 12, 2022

I'm seeing behavior where using be_successful hangs (rather than fails) when the request status is not a 200.

hangs:

      get "/items/#{id}"
      expect(response).to be_successful

Fails right away:

      get "/items/#{id}"
      expect(response).to have_http_status(:ok)

with:

     Failure/Error: expect(response).to have_http_status(:ok)
       expected the response to have status code :ok (200) but it was :forbidden (403)

Using:

    rspec-rails (5.1.1)
    rspec-core (3.11.0)
    rails (7.0.2.3)
@pirj
Copy link
Member

pirj commented Apr 12, 2022

Shouldn't it be expect(response).to be_ok?

Would expect(response.successful?).to be true hang, too?

@jcoyne
Copy link
Author

jcoyne commented Apr 12, 2022

@pirj I think that be_successful is true for any 2xx based response. (e.g. :ok, :created, :no_content)

When I use expect(response.successful?).to be true it fails right away as expected.

@darrenterhune
Copy link

I'm having this same problem when going to rails >= 7.0 from latest supported version 6.1.3.3 (at time of writing). I've narrowed it down to something that changed in ActionDispatch::Request with sessions. I mock auth (I'm using auth0 and mock_auth). It would set the session[:user_id] which is visible in a request spec prior to issuing the get()... but inside our auth logic at the controller level, that key is nil. So it 403's.

@pirj
Copy link
Member

pirj commented Jun 5, 2024

Does it hang for you, too, @darrenterhune ?

@darrenterhune
Copy link

I wouldn't say it hangs. It errors because I have an expectation of it to be 200 but it is a 403.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants