Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ def send_request(head, body)
end
end

def set_deferred_status(status, *args)
if status == :succeeded && !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
def unbind(reason = nil)
if !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
@request_signature = nil
remove_instance_variable(:@stubbed_webmock_response)

super
end
Expand Down
33 changes: 33 additions & 0 deletions spec/acceptance/em_http_request/em_http_request_spec.rb
Original file line number Diff line number Diff line change
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 { |req, res| urls << req.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