lib/pact/consumer/server.rb in pact-mock_service-0.8.1 vs lib/pact/consumer/server.rb in pact-mock_service-0.8.2

- old
+ new

@@ -68,48 +68,43 @@ return false end def run_default_server(app, port) require 'rack/handler/webrick' - Rack::Handler::WEBrick.run(app, webrick_opts) + Rack::Handler::WEBrick.run(app, webrick_opts) do |server| + @port = server[:Port] + end end def get_identity + return false unless @port http = Net::HTTP.new host, @port if options[:ssl] http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.get('/__identify__') end def webrick_opts - opts = {:Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0)} + opts = {Port: port.nil? ? 0 : port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0)} opts.merge!(ssl_opts) if options[:ssl] opts end def ssl_opts - { - :SSLEnable => true, - :SSLCertName => [ %w[CN localhost] ] - } + { SSLEnable: true, SSLCertName: [ %w[CN localhost] ] } end def boot unless responsive? - Pact::Server.ports[@app.object_id] = @port - - @server_thread = Thread.new do - run_default_server(@middleware, @port) - end - + @server_thread = Thread.new { run_default_server(@middleware, @port) } Timeout.timeout(60) { @server_thread.join(0.1) until responsive? } end rescue Timeout::Error raise "Rack application timed out during boot" else + Pact::Server.ports[@app.object_id] = @port self end - end end