Permalink
Browse files

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.  #1898

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
mame committed Jun 24, 2018
1 parent 103b506 commit be850d7b11017ba921f3f284dc9863c818e9ff86
Showing with 30 additions and 0 deletions.
  1. +30 −0 test/net/http/test_httpresponse.rb
@@ -427,6 +427,36 @@ def test_raises_exception_with_missing_reason
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)

0 comments on commit be850d7

Please sign in to comment.