Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubs for Typhoeus::Request#on_body #349

Merged
merged 4 commits into from Jan 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
Expand Up @@ -143,6 +143,13 @@ def self.request_hash(request_signature)
if webmock_response = ::WebMock::StubRegistry.instance.response_for_request(request_signature)
# ::WebMock::HttpLibAdapters::TyphoeusAdapter.stub_typhoeus(request_signature, webmock_response, self)
response = ::WebMock::HttpLibAdapters::TyphoeusAdapter.generate_typhoeus_response(request_signature, webmock_response)
if request.respond_to?(:on_headers)
request.execute_headers_callbacks(response)
end
if request.respond_to?(:streaming?) && request.streaming?
response.options[:response_body] = ""
request.on_body.each { |callback| callback.call(webmock_response.body, response) }
end
request.finish(response)
webmock_response.raise_error_if_any
res = false
Expand Down
33 changes: 33 additions & 0 deletions spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
Expand Up @@ -78,6 +78,39 @@
hydra.run
test.should == response_code
end

it "should call on_body with 2xx response" do
body = "on_body fired"
stub_request(:any, "example.com").to_return(:body => body)

test_body = nil
test_complete = nil
pending("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_body)
@request.on_body do |body, response|
test_body = body
end
@request.on_complete do |response|
test_complete = response.body
end
hydra.queue @request
hydra.run
test_body.should == body
test_complete.should == ""
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'})

test_headers = nil
pending("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_headers)
@request.on_headers do |response|
test_headers = response.headers
end
hydra.queue @request
hydra.run
test_headers.should include('X-Test' => '1')
end
end
end
end
Expand Down