diff --git a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb index a56fda33..80069dab 100644 --- a/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +++ b/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb @@ -172,7 +172,7 @@ def self.request_hash(request_signature) request.execute_headers_callbacks(response) end if request.respond_to?(:streaming?) && request.streaming? - response.options[:response_body] = "" + response.options[:response_body] = String.new request.on_body.each { |callback| callback.call(webmock_response.body, response) } end request.finish(response) diff --git a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb index a021d47a..067d58cc 100644 --- a/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +++ b/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb @@ -125,6 +125,19 @@ expect(test_complete).to eq("") end + it "should initialize the streaming response body with a mutible (non-frozen) string" do + skip("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_body) + + stub_request(:any, "example.com").to_return(body: "body") + + @request.on_body do |body_chunk, response| + response.body << body_chunk + end + hydra.queue @request + + expect{ hydra.run }.not_to raise_error + end + it "should call on_headers with 2xx response" do body = "on_headers fired" stub_request(:any, "example.com").to_return(body: body, headers: {'X-Test' => '1'})