Sha256: b689426c55d1f2eba024832037b516d89944ab5095535a4836e30376ea2c6541
Contents?: true
Size: 945 Bytes
Versions: 13
Compression:
Stored size: 945 Bytes
Contents
require 'spec_helper' require 'timeout' require 'webrick' # Patch WEBrick as it doesn't support PATCH (?) module WEBrick module HTTPServlet class ProcHandler alias do_PATCH do_GET end end end class TestServer def initialize(port, &block) @port = port @setup = block end def start return if @pid @pid = fork do WEBrick::HTTPServer.new( Port: @port, DocumentRoot: Dir.pwd, Logger: WEBrick::Log.new('/dev/null'), AccessLog: [nil, nil] ).tap do |server| @setup.call(server) server.start end end # wait until the child server is up Timeout.timeout(5) do loop do begin TCPSocket.new('localhost', '8000') rescue Errno::ECONNREFUSED next end break end end end def stop return unless @pid Process.kill('KILL', @pid) Process.wait(@pid) end end
Version data entries
13 entries across 13 versions & 1 rubygems