Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding condition in matching_hashes to change the way that two dates …

…are compared
  • Loading branch information...
commit 19670ebc2055888ff7f30383e7767fe4a13eaeee 1 parent 8f01af0
@fltiago authored
View
10 lib/webmock/request_pattern.rb
@@ -237,7 +237,11 @@ def matching_hashes?(query_parameters, pattern)
if actual.is_a?(Hash) && expected.is_a?(Hash)
return false unless matching_hashes?(actual, expected)
else
- return false unless expected === actual
+ if is_kind_of_date?(expected)
+ return false unless WebMock::Util::DateComparator.compare(actual, expected)
+ else
+ return false unless expected === actual
+ end
end
end
true
@@ -251,6 +255,10 @@ def normalize_hash(hash)
Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(hash).sort]
end
+ def is_kind_of_date?(date)
+ date.is_a?(Date) || date.is_a?(DateTime) || date.is_a?(Time)
+ end
+
end
class HeadersPattern
View
11 spec/acceptance/shared/request_expectations.rb
@@ -1,3 +1,5 @@
+require 'json'
+
shared_context "request expectations" do |*adapter_info|
describe "when request expectations are set" do
describe "when net connect is not allowed" do
@@ -258,6 +260,15 @@
}.should_not raise_error
end
+ it "should satisfy expectation even if json had date in the content" do
+ body_hash['date'] = Date.today
+ lambda {
+ http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
+ :body => body_hash.to_json)
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
+ }.should_not raise_error
+ end
+
it "should satisfy expectation even if json body contains date string" do
lambda {
http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
Please sign in to comment.
Something went wrong with that request. Please try again.