require_relative "utils"
require "webrick"
require "test/unit"

class WEBrick::TestProcHandler < Test::Unit::TestCase

  def test_proc
    config = { :DocumentRoot => File.dirname(__FILE__), }
    TestWEBrick.start_httpserver(config) do |server, addr, port, log|
      server.mount('/proc', WEBrick::HTTPServlet::ProcHandler,
                   lambda{|request, response|
                     response.content_type = "text/html"
                     response.body = 'Hello, WEBrick!'
                   })
      http = Net::HTTP.new(addr, port)
      req = Net::HTTP::Get.new("/proc")
      http.request(req){|res|
        assert_equal("200", res.code, log.call)
        assert_equal("text/html", res.content_type, log.call)
        assert_match(/Hello, WEBrick!/, res.body, log.call)
      }
    end
  end
end
