Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bblimke/webmock
base: master
...
head fork: tooky/webmock
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 29 additions and 3 deletions.
  1. +12 −3 lib/webmock/request_pattern.rb
  2. +17 −0 spec/request_pattern_spec.rb
View
15 lib/webmock/request_pattern.rb
@@ -80,12 +80,21 @@ def to_s
class BodyPattern
def initialize(pattern)
@pattern = pattern
+ if @pattern.is_a?(Hash)
+ pattern_uri = Addressable::URI.new
+ pattern_uri.query_values = @pattern
+ @pattern = pattern_uri.query_values
+ end
end
def matches?(uri)
- empty_string?(@pattern) && empty_string?(uri) ||
- @pattern == uri ||
- @pattern === uri
+ if (@pattern).is_a?(Hash)
+ @pattern.empty? || Addressable::URI.parse('?' + uri).query_values == @pattern
+ else
+ empty_string?(@pattern) && empty_string?(uri) ||
+ @pattern == uri ||
+ @pattern === uri
+ end
end
def to_s
View
17 spec/request_pattern_spec.rb
@@ -119,6 +119,23 @@ def match(request_signature)
end
+ describe "when body is supplied as a hash" do
+ it "should match post body params when body is expected with a hash" do
+ RequestPattern.new(:post, 'www.example.com', :body => {:a => '1', :b => 'five'}).
+ should match(RequestSignature.new(:post, "www.example.com", :body => 'a=1&b=five'))
+ end
+
+ it "should match different ordered body params" do
+ RequestPattern.new(:post, 'www.example.com', :body => {:a => '1', :b => 'five'}).
+ should match(RequestSignature.new(:post, "www.example.com", :body => 'b=five&a=1'))
+ end
+
+ it "should match complex body params" do
+ RequestPattern.new(:post, 'www.example.com', :body => {:a => {:nest => '1'}, :b => ['five', 'four', 'seven']}).
+ should match(RequestSignature.new(:post, "www.example.com", :body => 'a[nest]=1&b[]=five&b[]=four&b[]=seven'))
+ end
+ end
+
it "should match if request body and body pattern are the same" do

No commit comments for this range

Something went wrong with that request. Please try again.