Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow to stub Excon requests with query parameter Hash

  • Loading branch information...
commit cda6468ae24b533fdba876f0f2ce8d08b1a78487 1 parent e2369ac
Dimitrij Denissenko dim authored
19 lib/webmock/http_lib_adapters/excon_adapter.rb
View
@@ -22,9 +22,26 @@ def self.disable!
Excon.send(:const_set, :Connection, ExconConnection.superclass)
end
+
+ def self.to_query(hash)
+ string = ""
+ for key, values in hash
+ if values.nil?
+ string << key.to_s << '&'
+ else
+ for value in [*values]
+ string << key.to_s << '=' << CGI.escape(value.to_s) << '&'
+ end
+ end
+ end
+ string.chop! # remove trailing '&'
+ end
+
def self.build_request(params)
+ params = params.dup
+ method = (params.delete(:method) || :get).to_s.downcase.to_sym
+ params[:query] = to_query(params[:query]) if params[:query].is_a?(Hash)
uri = Addressable::URI.new(params).to_s
- method = (params[:method] || :get).to_s.downcase.to_sym
WebMock::RequestSignature.new method, uri, :body => params[:body], :headers => params[:headers]
end
6 spec/acceptance/excon/excon_spec.rb
View
@@ -5,5 +5,11 @@
describe "Excon" do
include ExconSpecHelper
include_context "with WebMock"
+
+ it 'should allow Excon requests to use query hash paramters' do
+ stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(:body => "abc")
+ Excon.get('http://example.com', :path => "resource/", :query => {:a => 1, :b => 2}).body.should == "abc"
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.