summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-24 09:31:09 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-24 09:31:09 +0000
commitbe850d7b11017ba921f3f284dc9863c818e9ff86 (patch)
treef707635ebcf97a34411d7fa8c5767b3c96219967 /test
parent103b5063f2568b1c16c1e5e2d234f783da7f73ff (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/net/http/test_httpresponse.rb30
1 files changed, 30 insertions, 0 deletions
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 '#<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)