Sha256: 55ee83728e20323b70728c08db8b5281037be4c95671348d5bf8bad29b3ba6cd

Contents?: true

Size: 687 Bytes

Versions: 4

Compression:

Stored size: 687 Bytes

Contents

require 'webrick'

class Servlet < WEBrick::HTTPServlet::AbstractServlet
  def initialize(server, json)
    super(server)
    @json = json
  end

  def do_GET(request, response)
    response.status = 200
    response['Content-Type'] = 'application/json'
    response.body = @json
  end
end

class DummyServer
  def initialize port, path, response
    @server = WEBrick::HTTPServer.new :Port => port,
      :AccessLog => [],
      :Logger => WEBrick::Log::new("/dev/null", 7)
    @server.mount path, Servlet, response
  end

  def start
    @pid = fork do
      trap 'INT' do @server.shutdown end
      @server.start
    end
  end

  def terminate
    Process.kill('INT', @pid)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pacto-0.2.5 spec/integration/utils/dummy_server.rb
pacto-0.2.4 spec/integration/utils/dummy_server.rb
pacto-0.2.3 spec/integration/utils/dummy_server.rb
pacto-0.2.2 spec/integration/utils/dummy_server.rb