From af6adc167735695b727489eeebb65a480a347eb3 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Sat, 15 Jun 2024 18:56:38 +0100 Subject: [PATCH] Revert "Fix Rack 3 support" --- .github/workflows/test.yml | 3 --- .../consumer/mock_service/rack_request_helper.rb | 2 +- lib/pact/consumer/server.rb | 6 +++++- lib/pact/mock_service/control_server/run.rb | 1 - lib/pact/mock_service/run.rb | 1 - lib/rack/handler/webbrick.rb | 12 ------------ pact-mock_service.gemspec | 8 ++------ 7 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 lib/rack/handler/webbrick.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5497721..f885e8e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,10 +9,7 @@ jobs: matrix: ruby_version: ["2.7", "3.0", "3.1", "3.2", "3.3"] os: ["ubuntu-latest","windows-latest","macos-latest"] - rack_version: ["2", "3"] runs-on: ${{ matrix.os }} - env: - RACK_VERSION: ${{ matrix.rack_version }} steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/lib/pact/consumer/mock_service/rack_request_helper.rb b/lib/pact/consumer/mock_service/rack_request_helper.rb index f9184d1..130fc15 100644 --- a/lib/pact/consumer/mock_service/rack_request_helper.rb +++ b/lib/pact/consumer/mock_service/rack_request_helper.rb @@ -24,7 +24,7 @@ def request_as_hash_from env end request[:headers] = headers_from env - body_string = request[:body]&.read || "" + body_string = request[:body].read if body_string.empty? request.delete :body diff --git a/lib/pact/consumer/server.rb b/lib/pact/consumer/server.rb index 7878e2d..767d837 100644 --- a/lib/pact/consumer/server.rb +++ b/lib/pact/consumer/server.rb @@ -1,7 +1,6 @@ require 'uri' require 'net/http' require 'rack' -require 'rack/handler/webbrick' # Copied shamelessly from Capybara # Used to run a mock service in a new thread when started by the AppManager or the ControlServer @@ -67,6 +66,11 @@ def responsive? end def run_default_server(app, port) + begin + require 'rack/handler/webrick' + rescue LoadError + require 'rackup/handler/webrick' + end Rack::Handler::WEBrick.run(app, **webrick_opts) do |server| @port = server[:Port] end diff --git a/lib/pact/mock_service/control_server/run.rb b/lib/pact/mock_service/control_server/run.rb index 8b654c7..0524e2b 100644 --- a/lib/pact/mock_service/control_server/run.rb +++ b/lib/pact/mock_service/control_server/run.rb @@ -1,6 +1,5 @@ require 'pact/mock_service/control_server/app' require 'pact/mock_service/server/webrick_request_monkeypatch' -require 'rack/handler/webbrick' module Pact module MockService diff --git a/lib/pact/mock_service/run.rb b/lib/pact/mock_service/run.rb index d0677f4..85f3166 100644 --- a/lib/pact/mock_service/run.rb +++ b/lib/pact/mock_service/run.rb @@ -5,7 +5,6 @@ require 'pact/mock_service/server/webrick_request_monkeypatch' require 'pact/specification_version' require 'pact/support/metrics' -require 'rack/handler/webbrick' module Pact module MockService diff --git a/lib/rack/handler/webbrick.rb b/lib/rack/handler/webbrick.rb deleted file mode 100644 index 6b5acc0..0000000 --- a/lib/rack/handler/webbrick.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Rack - module Handler - begin - require 'rack/handler/webrick' - WEBrick = Class.new(Rack::Handler::WEBrick) - rescue LoadError - require 'rackup/handler/webrick' - WEBrick = Class.new(Rackup::Handler::WEBrick) - end - end -end - diff --git a/pact-mock_service.gemspec b/pact-mock_service.gemspec index 5e46486..d5aebf5 100644 --- a/pact-mock_service.gemspec +++ b/pact-mock_service.gemspec @@ -20,12 +20,8 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.license = 'MIT' - if ENV['RACK_VERSION'] == '2' - gem.add_runtime_dependency 'rack', '>= 2.0', '< 3.0' - else - gem.add_runtime_dependency 'rack', '>= 3.0', '< 4.0' - gem.add_runtime_dependency 'rackup', '~> 2.0' - end + gem.add_runtime_dependency 'rack', '>= 2.0', '< 4.0' + gem.add_runtime_dependency 'rackup', '~> 2.0' gem.add_runtime_dependency 'rspec', '>=2.14' gem.add_runtime_dependency 'find_a_port', '~> 1.0.1' gem.add_runtime_dependency 'thor', '>= 0.19', '< 2.0'