Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

request_pattern should handle content_types that specify a charset #194

Merged
merged 1 commit into from

2 participants

@kjg

No description provided.

@bblimke
Owner

Thank you for this pull request. Looks good.

@bblimke bblimke merged commit 1e61a8c into bblimke:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  lib/webmock/request_pattern.rb
@@ -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 || "")) &&
View
7 spec/unit/request_pattern_spec.rb
@@ -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
Something went wrong with that request. Please try again.