spec/support/test_server.rb in patron-0.13.1 vs spec/support/test_server.rb in patron-0.13.3

- old
+ new

@@ -1,20 +1,26 @@ require 'rack' require 'puma' require 'rack/handler/puma' class PatronTestServer - APP = Rack::Builder.new { eval(File.read(File.dirname(__FILE__) + '/config.ru')) } + APP = Rack::Builder.new { eval(File.read(File.join(__dir__, 'config.ru'))) } def self.start(ssl = false, port = 9001 ) + # Reset the RSpec's SIGINT handler that does not really terminate after + # the first Ctrl+C pressed. + # Useful to terminate the forked process before Puma is actually started: + # it happens when running one particular example that does not need Puma + # so the specs are in fact finished before the Puma started. + Signal.trap('INT', 'EXIT') @ssl = ssl - keypath = File.expand_path(File.read(File.dirname(__FILE__) + '/../certs/privkey.pem')) - certpath = File.expand_path(File.read(File.dirname(__FILE__) + '/../certs/cacert.pem')) + keypath = File.join(__dir__, 'certs', 'privkey.pem') + certpath = File.join(__dir__, 'certs', 'cacert.pem') host = if ssl - 'ssl://127.0.0.1:%d?key=%s&cert=%s' % [port, keypath, certpath] + 'ssl://0.0.0.0:%d?key=%s&cert=%s' % [port, keypath, certpath] else - 'tcp://127.0.0.1:%d' % port + '0.0.0.0' end - Rack::Handler::Puma.run(APP, {:Port => port.to_i, :Verbose => true, :Host => '0.0.0.0'}) + Rack::Handler::Puma.run(APP, {:Port => port.to_i, :Verbose => true, :Host => host}) end end