diff --git a/capybara.gemspec b/capybara.gemspec index d33aac37d..9123925ef 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -61,6 +61,7 @@ Gem::Specification.new do |s| s.add_development_dependency('selenium-webdriver', ['~>4.8']) s.add_development_dependency('sinatra', ['>= 1.4.0']) s.add_development_dependency('uglifier') + s.add_development_dependency('webrick') s.add_development_dependency('yard', ['>= 0.9.0']) if RUBY_ENGINE == 'rbx' diff --git a/lib/capybara/registrations/servers.rb b/lib/capybara/registrations/servers.rb index 91e0e7b71..e7d72b96d 100644 --- a/lib/capybara/registrations/servers.rb +++ b/lib/capybara/registrations/servers.rb @@ -11,8 +11,17 @@ rescue LoadError # Rack 3 separated out the webrick handle - no way test currently in Capybaras automated # tests due to Sinatra not yet supporting Rack 3 - experimental - require 'rackup/handler/webrick' - Rackup + begin + # Rackup 2.2.0 has removed its dependency on webrick. The user + # must add it to their bundle themselves. + verbose, $VERBOSE = $VERBOSE, nil + require 'rackup/handler/webrick' + Rackup + rescue LoadError + raise LoadError, 'Capybara is unable to load `webrick` for its server, please add `webrick` to your project or specify a different server.' + ensure + $VERBOSE = verbose + end end options = { Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log.new(nil, 0) }.merge(options) base_class::Handler::WEBrick.run(app, **options) @@ -26,7 +35,7 @@ begin require 'rack/handler/puma' rescue LoadError - raise LoadError, 'Capybara is unable to load `puma` for its server, please add `puma` to your project or specify a different server via something like `Capybara.server = :webrick`.' + raise LoadError, 'Capybara is unable to load `puma` for its server, please add `puma` to your project or specify a different server.' end puma_rack_handler = defined?(Rackup::Handler::Puma) ? Rackup::Handler::Puma : Rack::Handler::Puma