Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…are compared
  • Loading branch information...
commit 19670ebc2055888ff7f30383e7767fe4a13eaeee 1 parent 8f01af0
Tiago Ferreira Lima authored
10 lib/webmock/request_pattern.rb
@@ -237,7 +237,11 @@ def matching_hashes?(query_parameters, pattern)
237 237 if actual.is_a?(Hash) && expected.is_a?(Hash)
238 238 return false unless matching_hashes?(actual, expected)
239 239 else
240   - return false unless expected === actual
  240 + if is_kind_of_date?(expected)
  241 + return false unless WebMock::Util::DateComparator.compare(actual, expected)
  242 + else
  243 + return false unless expected === actual
  244 + end
241 245 end
242 246 end
243 247 true
@@ -251,6 +255,10 @@ def normalize_hash(hash)
251 255 Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(hash).sort]
252 256 end
253 257
  258 + def is_kind_of_date?(date)
  259 + date.is_a?(Date) || date.is_a?(DateTime) || date.is_a?(Time)
  260 + end
  261 +
254 262 end
255 263
256 264 class HeadersPattern
11 spec/acceptance/shared/request_expectations.rb
... ... @@ -1,3 +1,5 @@
  1 +require 'json'
  2 +
1 3 shared_context "request expectations" do |*adapter_info|
2 4 describe "when request expectations are set" do
3 5 describe "when net connect is not allowed" do
@@ -258,6 +260,15 @@
258 260 }.should_not raise_error
259 261 end
260 262
  263 + it "should satisfy expectation even if json had date in the content" do
  264 + body_hash['date'] = Date.today
  265 + lambda {
  266 + http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
  267 + :body => body_hash.to_json)
  268 + a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
  269 + }.should_not raise_error
  270 + end
  271 +
261 272 it "should satisfy expectation even if json body contains date string" do
262 273 lambda {
263 274 http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},

0 comments on commit 19670eb

Please sign in to comment.
Something went wrong with that request. Please try again.