Skip to content
This repository

Fix em-http-request callback triggering #196

Merged
merged 1 commit into from almost 2 years ago

2 participants

Jon Leighton Bartosz Blimke
Jon Leighton

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.

Jon Leighton 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
Bartosz Blimke
Owner

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

Bartosz Blimke bblimke merged commit e962df7 into from
Bartosz Blimke bblimke closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 23, 2012
Jon Leighton 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
This page is out of date. Refresh to see the latest.
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)
105 105 self
106 106 elsif WebMock.net_connect_allowed?(request_signature.uri)
107 107 send_request_without_webmock(head, body)
108   - callback {
109   - if WebMock::CallbackRegistry.any_callbacks?
110   - webmock_response = build_webmock_response
111   - WebMock::CallbackRegistry.invoke_callbacks(
112   - {:lib => :em_http_request, :real_request => true},
113   - request_signature,
114   - webmock_response)
115   - end
116   - }
117   - self
118 108 else
119 109 raise WebMock::NetConnectNotAllowedError.new(request_signature)
120 110 end
@@ -123,6 +113,18 @@ def send_request_with_webmock(head, body)
123 113 alias_method :send_request_without_webmock, :send_request
124 114 alias_method :send_request, :send_request_with_webmock
125 115
  116 + def set_deferred_status(status, *args)
  117 + if status == :succeeded && !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
  118 + webmock_response = build_webmock_response
  119 + WebMock::CallbackRegistry.invoke_callbacks(
  120 + {:lib => :em_http_request, :real_request => true},
  121 + request_signature,
  122 + webmock_response)
  123 + end
  124 +
  125 + super
  126 + end
  127 +
126 128 def request_signature
127 129 @request_signature ||= build_request_signature
128 130 end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.