Permalink
Browse files

Use global callbacks instead global_hooks.

  • Loading branch information...
1 parent 4498816 commit 8ba313e66dab0deeecea8bd331b7de58147c670f @i0rek committed Aug 23, 2012
Showing with 7 additions and 10 deletions.
  1. +7 −10 lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
View
17 lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
@@ -29,17 +29,13 @@ def self.disabled?
end
def self.add_after_request_callback
- unless Typhoeus::Hydra.
- global_hooks[:after_request_before_on_complete].
- include?(AFTER_REQUEST_CALLBACK)
- Typhoeus::Hydra.
- global_hooks[:after_request_before_on_complete] << AFTER_REQUEST_CALLBACK
+ unless Typhoeus.on_complete.include?(AFTER_REQUEST_CALLBACK)
+ Typhoeus.on_complete << AFTER_REQUEST_CALLBACK
end
end
def self.remove_after_request_callback
- Typhoeus::Hydra.global_hooks[:after_request_before_on_complete].
- delete_if {|v| v == AFTER_REQUEST_CALLBACK }
+ Typhoeus.on_complete.delete_if {|v| v == AFTER_REQUEST_CALLBACK }
end
def self.build_request_signature(req)
@@ -118,12 +114,13 @@ def self.request_hash(request_signature)
hash
end
- AFTER_REQUEST_CALLBACK = Proc.new do |request|
+ AFTER_REQUEST_CALLBACK = Proc.new do |response|
+ request = response.request
request_signature = request.instance_variable_get(:@__webmock_request_signature)
webmock_response =
::WebMock::HttpLibAdapters::TyphoeusAdapter.
- build_webmock_response(request.response)
- if request.response.mock?
+ build_webmock_response(response)
+ if response.mock
WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :typhoeus},
request_signature,

0 comments on commit 8ba313e

Please sign in to comment.