testing Response#read

This commit is contained in:
HoneyryderChuck 2020-03-09 00:37:33 +00:00
parent 51e1994f56
commit aebadc8bc9
4 changed files with 15 additions and 6 deletions

View File

@ -28,14 +28,12 @@ module HTTPX
# number of seconds after which one can retry the request
def_option(:retry_after) do |num|
# return early if callable
if num.respond_to?(:call)
num
else
unless num.respond_to?(:call)
num = Integer(num)
raise Error, ":retry_after must be positive" unless num.positive?
num
end
num
end
def_option(:max_retries) do |num|

View File

@ -103,6 +103,8 @@ module HTTPX
def read(*args)
return unless @buffer
rewind
@buffer.read(*args)
end

View File

@ -51,7 +51,7 @@ module HTTPX
stream.refuse
end
def fetch_response(request, connections, options)
def fetch_response(request, _, _)
@responses.delete(request)
end

View File

@ -49,6 +49,15 @@ class ResponseTest < Minitest::Test
assert body3 == "", "HEAD requets body must be empty"
end
def test_response_body_read
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), threshold_size: 1024)
body1.write("foo")
assert body1.bytesize == 3
assert body1.read(1), "f"
assert body1.read(1), "o"
assert body1.read(1), "o"
end
def test_response_body_each
body1 = Response::Body.new(Response.new(request, 200, "2.0", {}), threshold_size: 1024)
body1.write("foo")