I'd like to adjust the puma configuration when running Capybara tests. Changing settings in .env, .env.test (I use dotenv), or config/puma.rb has no effect.
Where can I change the configuration?
Rails 5.1, poltergeist 1.15.0, capybara 2.14.0, puma 2.8.2
In ApplicationSystemTestCase
, you can configure by passing options
to the default :puma
server used by Rails in setup
.
AFAIK, this will work for any options, but I've only used
Silent: true
to silence the puma startup outputThread: '1:1'
to configure the puma process to only use one threadHere's how I've setup up rails systems tests to run inside docker containers:
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { url: "http://selenium:4444/wd/hub" }
def setup
Capybara.server_host = '0.0.0.0' # bind to all interfaces
Capybara.server = :puma, { Silent: true, Threads: '1:1' }
host! "http://#{IPSocket.getaddress(Socket.gethostname)}"
super
end
end
Generally with Capybara you configure the server in a register_server block. The :puma server definition Capybara provides is
Capybara.register_server :puma do |app, port, host|
require 'rack/handler/puma'
Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: "0:4")
end
If you're using Rails 5.1 system testing it has added a layer of abstraction on top of that with server configuration being done in ActionDispatch::SystemTesting::Server#register which is defined as
def register
Capybara.register_server :rails_puma do |app, port, host|
Rack::Handler::Puma.run(app, Port: port, Threads: "0:1")
end
end
Either way you should be able to either overwrite one of the current server registrations
Capybara.register_server :rails_puma do |app, port,host|
Rack::Handler::Puma.run(app, ...custom settings...)
end
or configure your own
Capybara.register_server :my_custom_puma do |app, port, host|
Rack::Handler::Puma.run(app, ...custom settings...)
end
Capybara.server = :my_custom_puma
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With