Skip to content

Commit 2f692af

Browse files
committed
Ensure puma config load process is respected
1 parent 0480f90 commit 2f692af

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/capybara/registrations/servers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
# Therefore construct and run the Server instance ourselves.
3939
# puma_rack_handler.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
4040
default_options = { Host: host, Port: port, Threads: '0:4', workers: 0, daemon: false }
41-
options = default_options.merge(options)
41+
override_options = { config_files: ['-'] }
42+
options = default_options.merge(options).merge(override_options)
4243

4344
conf = puma_rack_handler.config(app, options)
45+
conf.load
4446
conf.clamp
4547

4648
puma_ver = Gem::Version.new(Puma::Const::PUMA_VERSION)

spec/server_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4+
require 'puma'
45

56
RSpec.describe Capybara::Server do
67
it 'should spool up a rack server' do
@@ -102,7 +103,6 @@
102103
it 'should call #clamp on the puma configuration to ensure that environment is a string' do
103104
Capybara.server = :puma
104105
app_proc = proc { |_env| [200, {}, ['Hello Puma!']] }
105-
require 'puma'
106106
allow(Puma::Server).to receive(:new).and_wrap_original do |method, app, events, options|
107107
# If #clamp is not called on the puma config then this will be a Proc
108108
expect(options.fetch(:environment)).to be_a(String)
@@ -118,6 +118,25 @@
118118
Capybara.server = :default
119119
end
120120

121+
it 'should ignore puma config files' do
122+
Capybara.server = :puma
123+
Dir.mkdir('config') unless Dir.exist?('config')
124+
File.open('config/puma.rb', 'w') do |file|
125+
file.puts 'debug' # puma default is debug: false, which we don't override
126+
end
127+
allow(Puma::Server).to receive(:new).and_call_original
128+
app_proc = proc { |_env| [200, {}, ['Hello Puma!']] }
129+
server = described_class.new(app_proc).boot
130+
expect(Puma::Server).to have_received(:new).with(
131+
anything,
132+
anything,
133+
satisfy { |opts| opts.final_options[:debug] == false }
134+
)
135+
ensure
136+
Capybara.server = :default
137+
FileUtils.rm_rf('config')
138+
end
139+
121140
it 'should not emit any warnings when booting puma' do
122141
Capybara.server = :puma
123142
app_proc = proc { |_env| [200, {}, ['Hello Puma!']] }

0 commit comments

Comments
 (0)