mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
4e7c657fc8
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@185 19e92222-5c0b-0410-8929-a290d50e31e9
70 lines
1.5 KiB
Ruby
70 lines
1.5 KiB
Ruby
require 'test/unit'
|
|
require 'mongrel'
|
|
require 'benchmark'
|
|
|
|
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"
|
|
resp.body.write("test")
|
|
resp.finished
|
|
|
|
assert out.length > 0, "output didn't have data"
|
|
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
|
|
|
|
resp.finished
|
|
assert io.length > 0, "output didn't have data"
|
|
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
|
|
|
|
resp.finished
|
|
assert io.length > 0, "output didn't have data"
|
|
end
|
|
|
|
def test_response_file
|
|
contents = "PLAIN TEXT\r\nCONTENTS\r\n"
|
|
require 'tempfile'
|
|
tmpf = open("test_response_file", "wb")
|
|
tmpf.write(contents)
|
|
tmpf.rewind
|
|
|
|
io = StringIO.new
|
|
resp = HttpResponse.new(io)
|
|
resp.start(200) do |head,out|
|
|
head['Content-Type'] = 'text/plain'
|
|
resp.send_header
|
|
resp.send_file(tmpf.path)
|
|
end
|
|
io.rewind
|
|
tmpf.close
|
|
|
|
File.unlink("test_response_file")
|
|
|
|
assert io.length > 0, "output didn't have data"
|
|
assert io.read[-contents.length..-1] == contents, "output doesn't end with file payload"
|
|
end
|
|
end
|
|
|