运行Capybara时如何配置puma

运行Capybara时如何配置puma

本文介绍了运行Capybara时如何配置puma?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行水豚测试时,我想调整彪马的配置。更改.env,.env.test(我使用)或config / puma.rb中的设置没效果。

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.

在哪里可以更改配置?

Rails 5.1,poltergeist 1.15.0,capybara 2.14 .0,puma 2.8.2

Rails 5.1, poltergeist 1.15.0, capybara 2.14.0, puma 2.8.2

推荐答案

通常使用Capybara,您可以在register_server块中配置服务器。 Capybara提供的:puma服务器定义是

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

如果您使用的是Rails 5.1系统测试,则在服务器上添加了一层抽象配置已在
ActionDispatch :: SystemTesting :: Server#register中完成,定义为

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 inActionDispatch::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

或配置自己的

Capybara.register_server :my_custom_puma do |app, port, host|
  Rack::Handler::Puma.run(app, ...custom settings...)
end

Capybara.server = :my_custom_puma

这篇关于运行Capybara时如何配置puma?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:30