testing the client yield feature and the response body buffer transitions

This commit is contained in:
HoneyryderChuck 2018-01-28 21:59:08 +00:00
parent c4811c01f8
commit 57aa3b5159
2 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,14 @@ require_relative "test_helper"
class ClientTest < Minitest::Test
include HTTPX
def test_client_block
yielded = nil
Client.new do |cli|
yielded = cli
end
assert yielded.is_a?(Client), "client should have been yielded"
end
def test_client_plugin
klient_class = Class.new(Client)
klient_class.plugin(TestPlugin)

View File

@ -48,6 +48,19 @@ class ResponseTest < Minitest::Test
assert body1.each.to_a == %w(foobar), "must yield buffers"
end
def test_response_body_buffer
opts = { threshold_size: 10 }
body = Response::Body.new(Response.new(request, 200, "2.0", {}), opts)
body.extend(Module.new do
attr_reader :buffer
end)
assert body.buffer.nil?, "body should not buffer anything"
body.write("hello")
assert body.buffer.is_a?(StringIO), "body should buffer to memory"
body.write(" world")
assert body.buffer.is_a?(Tempfile), "body should buffer to file after going over threshold"
end
private
def request(verb=:get, uri="http://google.com")