From ee9f4d997483127330e7fb3b9ed8f8c6b1e48685 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Sat, 15 Jun 2024 20:20:38 +0100 Subject: [PATCH] test: upgrade to rack 3.x and add workaround to rack 3.1.x related: https://github.com/pact-foundation/pact-mock_service/pull/152 --- Gemfile | 1 + spec/lib/rack/webrick.rb | 12 ++++++++++++ spec/support/ssl_server.rb | 19 ++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 spec/lib/rack/webrick.rb diff --git a/Gemfile b/Gemfile index f5988e7..1671ea9 100644 --- a/Gemfile +++ b/Gemfile @@ -26,4 +26,5 @@ group :test do gem 'faraday', '~>2.0' gem 'faraday-retry', '~>2.0' gem 'rackup', '~> 2.1' + gem 'rack', '>= 3.0', '< 4.0' end diff --git a/spec/lib/rack/webrick.rb b/spec/lib/rack/webrick.rb new file mode 100644 index 0000000..54286f7 --- /dev/null +++ b/spec/lib/rack/webrick.rb @@ -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 + \ No newline at end of file diff --git a/spec/support/ssl_server.rb b/spec/support/ssl_server.rb index b8bbed8..4d1685a 100644 --- a/spec/support/ssl_server.rb +++ b/spec/support/ssl_server.rb @@ -32,11 +32,20 @@ def webrick_opts port require "webrick" require "webrick/https" require "rack" - require "rackup/handler/webrick" + begin + # For rack <= 3.0.x + require 'rack/handler/webrick' + opts = webrick_opts(4444) + Rack::Handler::WEBrick.run(app, **opts) do |server| + @server = server + end + rescue LoadError + # For rack >= 3.1.x + require 'rackup/handler/webrick' + opts = webrick_opts(4444) - opts = webrick_opts(4444) - - Rack::Handler::WEBrick.run(app, **opts) do |server| - @server = server + Rackup::Handler::WEBrick.run(app, **opts) do |server| + @server = server + end end end