diff --git a/lib/capybara/registrations/servers.rb b/lib/capybara/registrations/servers.rb index a3ee6799..14391185 100644 --- a/lib/capybara/registrations/servers.rb +++ b/lib/capybara/registrations/servers.rb @@ -28,6 +28,7 @@ Capybara.register_server :puma do |app, port, host, **options| options = default_options.merge(options) conf = Rack::Handler::Puma.config(app, options) + conf.clamp events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio puma_ver = Gem::Version.new(Puma::Const::PUMA_VERSION) diff --git a/spec/server_spec.rb b/spec/server_spec.rb index c21979bc..486e7dbb 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -99,6 +99,21 @@ RSpec.describe Capybara::Server do expect(uri.to_hash).to include(scheme: 'http', host: server.host, port: server.port) end + it 'should call #clamp on the puma configuration to ensure that environment is a string' do + Capybara.server = :puma + app_proc = proc { |_env| [200, {}, ['Hello Puma!']] } + require 'puma' + allow(Puma::Server).to receive(:new).and_wrap_original do |method, app, events, options| + # If #clamp is not called on the puma config then this will be a Proc + expect(options.fetch(:environment)).to eq 'development' + method.call(app, events, options) + end + described_class.new(app_proc).boot + expect(Puma::Server).to have_received(:new) + ensure + Capybara.server = :default + end + it 'should support SSL' do key = File.join(Dir.pwd, 'spec', 'fixtures', 'key.pem') cert = File.join(Dir.pwd, 'spec', 'fixtures', 'certificate.pem')