Skip to content

Commit

Permalink
Added streaming support for em-http-request
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Blimke committed Jun 20, 2010
1 parent 4398871 commit 90bdfe9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/webmock/http_lib_adapters/em_http_request.rb
Expand Up @@ -15,6 +15,10 @@ def setup(response, uri, error = nil)
succeed(self)
end
end

def stream(&blk)
blk.call(@response)
end

def unbind
end
Expand Down
30 changes: 17 additions & 13 deletions spec/em_http_request_spec.rb
Expand Up @@ -2,22 +2,26 @@
require 'webmock_spec'
require 'ostruct'

unless RUBY_PLATFORM =~ /java/
require 'em_http_request_spec_helper'
require 'em_http_request_spec_helper'

describe "Webmock with EM::HttpRequest" do
include EMHttpRequestSpecHelper
describe "Webmock with EM::HttpRequest" do
include EMHttpRequestSpecHelper

it_should_behave_like "WebMock"
it_should_behave_like "WebMock"

it "should work with block"

it "should work with streaming"

it "should work with optional query params" do
stub_http_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3", :query => {"a" => ["b", "c"]}).body.should == "abc"
end
it "should work with streaming" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
response = ""
EM.run {
http = EventMachine::HttpRequest.new('http://www.example.com/').get
http.stream { |chunk| response = chunk; EM.stop }
}
response.should == "abc"
end

it "should work with optional query params" do
stub_http_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3", :query => {"a" => ["b", "c"]}).body.should == "abc"
end

end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'httpclient'
require 'patron' unless RUBY_PLATFORM =~ /java/
require 'em-http' unless RUBY_PLATFORM =~ /java/
require 'em-http'

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Expand Down

0 comments on commit 90bdfe9

Please sign in to comment.