2006-01-28 14:34:12 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mongrel'
|
2006-03-19 18:31:30 -05:00
|
|
|
require 'benchmark'
|
2006-01-28 14:34:12 -05:00
|
|
|
|
|
|
|
include Mongrel
|
|
|
|
|
|
|
|
class ResponseTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_response_headers
|
|
|
|
out = StringIO.new
|
|
|
|
resp = HttpResponse.new(out)
|
|
|
|
resp.status = 200
|
|
|
|
resp.header["Accept"] = "text/plain"
|
|
|
|
resp.header["X-Whatever"] = "stuff"
|
2006-01-28 15:27:34 -05:00
|
|
|
resp.body.write("test")
|
2006-01-28 14:34:12 -05:00
|
|
|
resp.finished
|
|
|
|
|
2006-01-28 15:27:34 -05:00
|
|
|
assert out.length > 0, "output didn't have data"
|
2006-01-28 14:34:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_response_200
|
|
|
|
io = StringIO.new
|
|
|
|
resp = HttpResponse.new(io)
|
|
|
|
resp.start do |head,out|
|
|
|
|
head["Accept"] = "text/plain"
|
|
|
|
out.write("tested")
|
|
|
|
out.write("hello!")
|
|
|
|
end
|
2006-03-26 18:57:11 -05:00
|
|
|
|
|
|
|
resp.finished
|
2006-01-28 15:27:34 -05:00
|
|
|
assert io.length > 0, "output didn't have data"
|
2006-01-28 14:34:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_response_404
|
|
|
|
io = StringIO.new
|
|
|
|
|
|
|
|
resp = HttpResponse.new(io)
|
|
|
|
resp.start(404) do |head,out|
|
|
|
|
head['Accept'] = "text/plain"
|
|
|
|
out.write("NOT FOUND")
|
|
|
|
end
|
|
|
|
|
2006-03-26 18:57:11 -05:00
|
|
|
resp.finished
|
2006-01-28 15:27:34 -05:00
|
|
|
assert io.length > 0, "output didn't have data"
|
2006-01-28 14:34:12 -05:00
|
|
|
end
|
|
|
|
|
2006-03-19 18:31:30 -05:00
|
|
|
|
2006-01-28 14:34:12 -05:00
|
|
|
end
|
|
|
|
|