From 6f48859a607efcc4498e93d8026874af5afd4fb7 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 6 Apr 2018 10:54:31 -0700 Subject: [PATCH] Improve error message when Puma isn't available --- UPGRADING.md | 8 ++++++++ lib/capybara.rb | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/UPGRADING.md b/UPGRADING.md index 23c4d0f9..6b24adfb 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,5 +1,13 @@ # Upgrading from Capybara 2.x to 3.x +## Server + +Capybara 3 changes the default server to Puma. If you do not use `Puma` in your project you can +revert to the previous default of WEBRick by specifying + +```ruby +Capybara.server = :webrick +``` ## Finders diff --git a/lib/capybara.rb b/lib/capybara.rb index 5b699e03..af45d6c9 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -438,7 +438,11 @@ Capybara.register_server :webrick do |app, port, host, **options| end Capybara.register_server :puma do |app, port, host, **options| - require 'rack/handler/puma' + 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`." + end # If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests. # Therefore construct and run the Server instance ourselves. # Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))