rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.19k stars 1.04k forks source link

Request specs fail after upgrading to Rack 3 #2814

Open cjamison opened 4 days ago

cjamison commented 4 days ago

We have a number of request specs for our API and after upgrading Rack from 2.x to 3.x, they all started failing with:

     Failure/Error: get "/api/v1/products/1", headers: @headers

     NoMethodError:
       undefined method `read' for nil:NilClass

The way to resolve these errors is to convert the get request to

get "/api/v1/products/1", headers: @headers, env: { 'rack.input' => StringIO.new }

However, it seems very verbose to add this to each request. Am I missing an easier / better way to avoid this error?

This is on rspec-rails 7.1.0 and rspec-core 3.13.2.

JonRowe commented 3 days ago

:wave: We don't include any behaviour for this ourselves and rely on the upstream Rails / rack-test helpers, is Rack 3 supported by Rails 8? I think 7 is still pinned to 2.x isn't it?

cjamison commented 3 days ago

No, Rails 7 is not pinned to 2.x. At least 7.1 is not which is what we are using.

I see what happened on our end. We have another gem using/requiring Sinatra and at least Sinatra 4.1.1 is requiring rack >= 3.0.0. So, that is what caused our jump. I will see if we want to continue as things are or downgrade Sinatra to something not requiring rack 3.

JonRowe commented 2 days ago

My mistake 7.0 is, but not anything later, what version of Rack are you on? It seems like 3.1 made "rack.input" fully optional?

cjamison commented 2 days ago

Bundle installed rack 3.1.8. In spite of "rack.input" being optional in this version, it still gave me the error message without me adding it into the test.