How can I configure puma when running Capybara?

Viewed 6341

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

2 Answers

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 output
  • Thread: '1:1' to configure the puma process to only use one thread

Here'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
Related