mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
testing the client yield feature and the response body buffer transitions
This commit is contained in:
parent
c4811c01f8
commit
57aa3b5159
@ -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)
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user