Skip to content

Commit

Permalink
fix: Fix Rack > 3.0.0 support
Browse files Browse the repository at this point in the history
Now Rack::Handler has been moved to a seperate gem, we need to specify
it specifically. I’ve monkeypatched `Rack::Handler::WEBrick` to support
both use cases everywhere in the gem
  • Loading branch information
pezholio authored and YOU54F committed Jun 15, 2024
1 parent c75a2bb commit fab4a8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
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

0 comments on commit fab4a8f

Please sign in to comment.