Skip to content

Commit

Permalink
Merge pull request #1049 from etiennebarrie/dont-use-deprecated-rack-…
Browse files Browse the repository at this point in the history
…version

Don't use deprecated Rack::VERSION in Rack 3
  • Loading branch information
bblimke committed Feb 19, 2024
2 parents 0e3c8fb + b5660c8 commit 37c9de9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/webmock/rack_response.rb
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/spec_helper.rb
Expand Up @@ -22,6 +22,8 @@
require 'support/my_rack_app'
require 'support/failures'

Warning[:deprecated] = true if Warning.respond_to?(:[]=)

CURL_EXAMPLE_OUTPUT_PATH = File.expand_path('../support/example_curl_output.txt', __FILE__)

RSpec.configure do |config|
Expand Down
2 changes: 2 additions & 0 deletions spec/support/my_rack_app.rb
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
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 37c9de9

Please sign in to comment.