ruby-changes:51528
From: mame <ko1@a...>
Date: Sun, 24 Jun 2018 18:37:53 +0900 (JST)
Subject: [ruby-changes:51528] mame:r63738 (trunk): test/net/http/test_httpresponse.rb: add testcases for net/httpresponse
mame 2018-06-24 18:31:09 +0900 (Sun, 24 Jun 2018) New Revision: 63738 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63738 Log: 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 Modified files: trunk/test/net/http/test_httpresponse.rb Index: test/net/http/test_httpresponse.rb =================================================================== --- test/net/http/test_httpresponse.rb (revision 63737) +++ test/net/http/test_httpresponse.rb (revision 63738) @@ -427,6 +427,36 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpresponse.rb#L427 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/