diff --git a/lib/webmock/matchers/hash_including_matcher.rb b/lib/webmock/matchers/hash_including_matcher.rb index 6ebb1a840..0d8f53ed5 100644 --- a/lib/webmock/matchers/hash_including_matcher.rb +++ b/lib/webmock/matchers/hash_including_matcher.rb @@ -8,7 +8,12 @@ def initialize(expected) end def ==(actual) - @expected.all? {|k,v| actual.has_key?(k) && v === actual[k]} + @expected.all? do |k,v| + actual_value = actual.respond_to?(:has_key?) ? actual[k] : actual + actual_value = WebMock::Util::QueryValueStringifier.stringify(actual_value) + actual.has_key?(k) && WebMock::Util::QueryValueStringifier.stringify(v) === actual_value + end + rescue NoMethodError false end diff --git a/lib/webmock/util/query_value_stringifier.rb b/lib/webmock/util/query_value_stringifier.rb index 6c821fd14..85848000d 100644 --- a/lib/webmock/util/query_value_stringifier.rb +++ b/lib/webmock/util/query_value_stringifier.rb @@ -3,14 +3,18 @@ class QueryValueStringifier class << self def stringify(value) case value - when String + when String, NilClass value when Array value.map { |v| stringify(v) } when Hash Hash[value.map { |k, v| [k, stringify(v)] }] - else + when Integer, TrueClass, FalseClass, Symbol value.to_s + when WebMock::Matchers::AnyArgMatcher, RSpec::Mocks::ArgumentMatchers::AnyArgMatcher + value + else + value end end end diff --git a/spec/hash_including_bug_spec.rb b/spec/hash_including_bug_spec.rb new file mode 100644 index 000000000..6ab63a45b --- /dev/null +++ b/spec/hash_including_bug_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" +begin + require "httparty" +rescue LoadError + @skip_specs = true +end + +unless @skip_specs + RSpec.describe "Hash including Bug" do + let!(:dummy_url) { 'http://dummyurl.com' } + + it "receive a request" do + stub_request(:get, dummy_url). + with(:query => hash_including({ param1: 5 })). + to_return(:body => 'body 1') + + expect( + HTTParty.get(dummy_url, { + query: { + :param1 => 5, + :param2 => 'random1' + } + }).body + ).to eq 'body 1' + end + end +end diff --git a/webmock.gemspec b/webmock.gemspec index c3b3f8eec..b94e31cef 100644 --- a/webmock.gemspec +++ b/webmock.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'excon', '>= 0.27.5' s.add_development_dependency 'minitest', '~> 5.0.0' s.add_development_dependency 'rdoc', ((RUBY_VERSION == '1.8.6') ? '<= 3.5.0' : '>3.5.0') + s.add_development_dependency 'httparty' if RUBY_VERSION >= "1.9.3" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")