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

Don't use deprecated Rack::VERSION in Rack 3 #1049

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/spec_helper.rb
Original file line number Diff line number Diff line change
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
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