Skip to content

Commit

Permalink
Don't use deprecated Rack::VERSION in Rack 3
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebarrie committed Feb 13, 2024
1 parent 0e3c8fb commit b3db600
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/webmock/rack_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def build_rack_env(request)
# Rack-specific variables
env['rack.input'] = StringIO.new(body)
env['rack.errors'] = $stderr
env['rack.version'] = Rack::VERSION
if !Rack.const_defined?(:RELEASE) || Rack::RELEASE < "3"
env['rack.version'] = Rack::VERSION
end
env['rack.url_scheme'] = uri.scheme
env['rack.run_once'] = true
env['rack.session'] = session
Expand Down
2 changes: 2 additions & 0 deletions spec/support/my_rack_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def self.call(env)
when ['GET', '/error']
env['rack.errors'].puts('Error!')
[500, {}, ['']]
when ['GET', '/env']
[200, {}, [JSON.dump(env)]]
else
[404, {}, ['']]
end
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/rack_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@
expect(response.body).to include('Good to meet you, Олег!')
end

it "should send or not a rack.version depending on the Rack version" do
request = WebMock::RequestSignature.new(:get, 'www.example.com/env')
response = @rack_response.evaluate(request)

expect(response.status.first).to eq(200)
body = JSON.parse(response.body)

if Gem.loaded_specs["rack"].version > Gem::Version.new("3.0.0")
expect(body).not_to include("rack.version")
else
expect(body).to include("rack.version")
end
end

describe 'rack error output' do
before :each do
@original_stderr = $stderr
Expand Down

0 comments on commit b3db600

Please sign in to comment.