1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/net/http/test_httpresponse.rb: add testcases for net/httpresponse

This change adds testcases for Response#inspect and #code_type, and
improves line coverage of lib/net/http/response.rb (91.8 % to 92.94 %).

A patch from @owlworks.  https://github.com/ruby/ruby/pull/1898

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-06-24 09:31:09 +00:00
parent 103b5063f2
commit be850d7b11

View file

@ -427,6 +427,36 @@ EOS
end
end
def test_read_code_type
res = Net::HTTPUnknownResponse.new('1.0', '???', 'test response')
assert_equal Net::HTTPUnknownResponse, res.code_type
res = Net::HTTPInformation.new('1.0', '1xx', 'test response')
assert_equal Net::HTTPInformation, res.code_type
res = Net::HTTPSuccess.new('1.0', '2xx', 'test response')
assert_equal Net::HTTPSuccess, res.code_type
res = Net::HTTPRedirection.new('1.0', '3xx', 'test response')
assert_equal Net::HTTPRedirection, res.code_type
res = Net::HTTPClientError.new('1.0', '4xx', 'test response')
assert_equal Net::HTTPClientError, res.code_type
res = Net::HTTPServerError.new('1.0', '5xx', 'test response')
assert_equal Net::HTTPServerError, res.code_type
end
def test_inspect_response
res = Net::HTTPUnknownResponse.new('1.0', '???', 'test response')
assert_equal '#<Net::HTTPUnknownResponse ??? test response readbody=false>', res.inspect
res = Net::HTTPUnknownResponse.new('1.0', '???', 'test response')
socket = Net::BufferedIO.new(StringIO.new('test body'))
res.reading_body(socket, true) {}
assert_equal '#<Net::HTTPUnknownResponse ??? test response readbody=true>', res.inspect
end
private
def dummy_io(str)