Skip to content

Commit

Permalink
Merge pull request #155 from pact-foundation/revertrevert
Browse files Browse the repository at this point in the history
fix: Rack 3 support
  • Loading branch information
YOU54F authored Jun 15, 2024
2 parents 9bfdd03 + f6b1869 commit ce6f003
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/consumer/mock_service/rack_request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions lib/pact/consumer/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down Expand Up @@ -66,11 +67,6 @@ 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
Expand Down
1 change: 1 addition & 0 deletions lib/pact/mock_service/control_server/run.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact/mock_service/control_server/app'
require 'pact/mock_service/server/webrick_request_monkeypatch'
require 'rack/handler/webbrick'

module Pact
module MockService
Expand Down
1 change: 1 addition & 0 deletions lib/pact/mock_service/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'pact/mock_service/server/webrick_request_monkeypatch'
require 'pact/specification_version'
require 'pact/support/metrics'
require 'rack/handler/webbrick'

module Pact
module MockService
Expand Down
12 changes: 12 additions & 0 deletions lib/rack/handler/webbrick.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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

8 changes: 6 additions & 2 deletions pact-mock_service.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.license = 'MIT'

gem.add_runtime_dependency 'rack', '>= 2.0', '< 4.0'
gem.add_runtime_dependency 'rackup', '~> 2.0'
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 'rspec', '>=2.14'
gem.add_runtime_dependency 'find_a_port', '~> 1.0.1'
gem.add_runtime_dependency 'thor', '>= 0.19', '< 2.0'
Expand Down

0 comments on commit ce6f003

Please sign in to comment.