Skip to content

Commit

Permalink
Add a failing spec demonstrating a bug in the em-http-request adapter.
Browse files Browse the repository at this point in the history
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
myronmarston committed May 25, 2012
1 parent 6927943 commit a42d463
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/acceptance/em_http_request/em_http_request_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit a42d463

Please sign in to comment.