From be850d7b11017ba921f3f284dc9863c818e9ff86 Mon Sep 17 00:00:00 2001 From: mame Date: Sun, 24 Jun 2018 09:31:09 +0000 Subject: 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 --- test/net/http/test_httpresponse.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/net/http/test_httpresponse.rb') diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb index 29c38b2bc0..a03bb2e152 100644 --- a/test/net/http/test_httpresponse.rb +++ b/test/net/http/test_httpresponse.rb @@ -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 '#', 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 '#', res.inspect + end + private def dummy_io(str) -- cgit v1.2.3