Skip to content

Commit

Permalink
Merge pull request bblimke#194 from kjg/request_pattern_charset
Browse files Browse the repository at this point in the history
request_pattern should handle content_types that specify a charset
  • Loading branch information
bblimke committed Jul 23, 2012
2 parents bca9e74 + 824c336 commit 1e61a8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/webmock/request_pattern.rb
Expand Up @@ -27,6 +27,7 @@ def with(options = {}, &block)

def matches?(request_signature)
content_type = request_signature.headers['Content-Type'] if request_signature.headers
content_type = content_type.split(';').first if content_type
@method_pattern.matches?(request_signature.method) &&
@uri_pattern.matches?(request_signature.uri) &&
(@body_pattern.nil? || @body_pattern.matches?(request_signature.body, content_type || "")) &&
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/request_pattern_spec.rb
Expand Up @@ -358,6 +358,13 @@ def match(request_signature)
should_not match(WebMock::RequestSignature.new(:post, "www.example.com",
:headers => {:content_type => 'application/xml'}, :body => "foo bar"))
end

it "matches when the content type include a charset" do
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml;charset=UTF-8'},
:body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))

end
end
end

Expand Down

0 comments on commit 1e61a8c

Please sign in to comment.