Small patch to make mocked EventMachine::HttpRequest a bit more complete #70

Merged
1 commit merged into from Jan 12, 2011
View
2 lib/webmock/http_lib_adapters/em_http_request.rb
@@ -10,7 +10,7 @@ class WebMockHttpRequest < EventMachine::HttpRequest
class WebMockHttpClient < EventMachine::HttpClient
def setup(response, uri, error = nil)
- @uri = uri
+ @last_effective_url = @uri = uri
if error
on_error(error)
fail(self)
View
21 spec/em_http_request_spec.rb
@@ -30,5 +30,26 @@
http_request(:get, "http://www.example.com/?x=3", :query => "a[]=b&a[]=c").body.should == "abc"
end
+ describe "mocking EM::HttpClient API" do
+ before { stub_http_request(:get, "www.example.com/") }
+ subject do
+ client = nil
+ EM.run do
+ client = EventMachine::HttpRequest.new('http://www.example.com/').get
+ client.callback { EM.stop }
+ client.errback { failed }
+ end
+ client
+ end
+
+ it 'should support #uri' do
+ subject.uri.should == Addressable::URI.parse('http://www.example.com/')
+ end
+
+ it 'should support #last_effective_url' do
+ subject.last_effective_url.should == Addressable::URI.parse('http://www.example.com/')
+ end
+ end
+
end
end