Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a failing spec demonstrating a bug in the em-http-request adapter.

When a request is made to a URL that returns a 3xx response and the
:redirects option is set, the globally_stub_request/after_request
hooks are not paired properly.  Both hooks should receive the original
request and the redirect-following request.

This spec should probably be re-written to use the local webmock
server, but I couldn't figure out how to get it to conditionally
send a redirect response since it writes directly to the socket
and doesn't (as far as I can tell) have the request info available
in that scope...so there's not easy way to have it send a different
response for different requests :(.

See myronmarston/vcr#171 for the original VCR issue that caused
me to investigate this bug.
  • Loading branch information...
commit a42d4634d10d4f8bf7fb1ad50f789aa0559b7ad9 1 parent 6927943
@myronmarston myronmarston authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 spec/acceptance/em_http_request/em_http_request_spec.rb
View
33 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -11,6 +11,39 @@
include_context "with WebMock", :no_status_message
+ context 'when a real request is made and redirects are followed' do
+ before { WebMock.allow_net_connect! }
+
+ # This url redirects to the https URL.
+ let(:http_url) { "http://raw.github.com:80/gist/fb555cb593f3349d53af/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist" }
+ let(:https_url) { http_url.gsub('http', 'https').gsub('80', '443') }
+
+ def make_request
+ EM.run do
+ request = EM::HttpRequest.new(http_url).get(:redirects => 1)
+ request.callback { EM.stop }
+ end
+ end
+
+ it "invokes the globally_stub_request hook with both requests" do
+ urls = []
+ WebMock.globally_stub_request { |r| urls << r.uri.to_s; nil }
+
+ make_request
+
+ urls.should eq([http_url, https_url])
+ end
+
+ it 'invokes the after_request hook with both requests' do
+ urls = []
+ WebMock.after_request { |r| urls << r.uri.to_s }
+
+ make_request
+
+ urls.should eq([http_url, https_url])
+ end
+ end
+
#functionality only supported for em-http-request 1.x
if defined?(EventMachine::HttpConnection)
describe "with middleware" do
Please sign in to comment.
Something went wrong with that request. Please try again.