Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix em-http-request callback triggering #196

Merged
merged 1 commit into from

2 participants

@jonleighton

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.

@jonleighton jonleighton 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.
71e7baf
@bblimke
Owner

Thanks for this fix. No idea what's the best way to test that either :)

@bblimke bblimke merged commit e962df7 into bblimke:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 23, 2012
  1. @jonleighton

    Fix em-http-request callback triggering

    jonleighton authored
    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.
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.