Skip to content
Browse files

Fix em-http-request callback triggering

Previously, if there were other EM::Deferred callbacks registered, they
might execute before WebMock's callback and raise an exception. This
would prevent the WebMock callback ever running, even though there was a
successful request.

Overriding set_deferred_status prevents this by triggering WebMock's
callbacks before running any of the EM::Deferred callbacks.

Sorry, I have no idea how to test this.
  • Loading branch information...
1 parent 887bf32 commit 71e7baf8c38c08735bea8b9bfe25fa003eeda12c @jonleighton committed Jul 23, 2012
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb
View
22 lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb
@@ -105,16 +105,6 @@ def send_request_with_webmock(head, body)
self
elsif WebMock.net_connect_allowed?(request_signature.uri)
send_request_without_webmock(head, body)
- callback {
- if WebMock::CallbackRegistry.any_callbacks?
- webmock_response = build_webmock_response
- WebMock::CallbackRegistry.invoke_callbacks(
- {:lib => :em_http_request, :real_request => true},
- request_signature,
- webmock_response)
- end
- }
- self
else
raise WebMock::NetConnectNotAllowedError.new(request_signature)
end
@@ -123,6 +113,18 @@ def send_request_with_webmock(head, body)
alias_method :send_request_without_webmock, :send_request
alias_method :send_request, :send_request_with_webmock
+ def set_deferred_status(status, *args)
+ if status == :succeeded && !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
+ webmock_response = build_webmock_response
+ WebMock::CallbackRegistry.invoke_callbacks(
+ {:lib => :em_http_request, :real_request => true},
+ request_signature,
+ webmock_response)
+ end
+
+ super
+ end
+
def request_signature
@request_signature ||= build_request_signature
end

0 comments on commit 71e7baf

Please sign in to comment.
Something went wrong with that request. Please try again.