From 824c33687acf2f3280beddedce13a6bd808e70f3 Mon Sep 17 00:00:00 2001 From: Kevin Glowacz Date: Thu, 12 Jul 2012 13:42:39 -0500 Subject: [PATCH] request_pattern should handle content_types that specify a charset --- lib/webmock/request_pattern.rb | 1 + spec/unit/request_pattern_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/webmock/request_pattern.rb b/lib/webmock/request_pattern.rb index 0ea2fa2c1..0415acc6b 100644 --- a/lib/webmock/request_pattern.rb +++ b/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 || "")) && diff --git a/spec/unit/request_pattern_spec.rb b/spec/unit/request_pattern_spec.rb index db7d2c723..9ba0ba07f 100644 --- a/spec/unit/request_pattern_spec.rb +++ b/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 => "\n \n e\n f\n \n\n")) + + end end end