1 # Copyright (c) 2005 Zed A. Shaw
2 # You can redistribute it and/or modify it under the same terms as Ruby.
4 # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
5 # for more information.
7 require 'test/test_helper'
11 class ResponseTest < Test::Unit::TestCase
13 def test_response_headers
15 HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]])
18 assert out.length > 0, "output didn't have data"
21 def test_response_OFS_set
25 HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]])
28 assert ! resp.include?("\f\v"), "output didn't use $, ($OFS)"
35 HttpResponse.write(io, [200, {}, []])
37 assert io.length > 0, "output didn't have data"
40 def test_response_with_default_reason
43 HttpResponse.write(io, [code, {}, []])
45 lines = io.string.split(/\r\n/)
46 assert_match(/.* #{HTTP_STATUS_CODES[code]}$/, lines.first,
47 "wrong default reason phrase")
50 def test_rack_multivalue_headers
52 HttpResponse.write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []])
54 assert_match(/^X-Whatever: stuff\r\nX-Whatever: bleh\r\n/, out.string)
58 expect_body = %w(1 2 3 4).join("\n")
59 body = StringIO.new(expect_body)
62 HttpResponse.write(out,[200, {}, body])
65 assert_match(expect_body, out.string.split(/\r\n/).last)