Fix em-http-request callback triggering #196

Merged
merged 1 commit into from Jul 23, 2012
@@ -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