WebMock::API.hash_including not working (and causes warnings in Ruby 2.0) #329

steookk opened this Issue Nov 7, 2013 · 4 comments


None yet

3 participants

steookk commented Nov 7, 2013

It gives these warnings (from what I understood after some searches these warnings only occur in Ruby 2.0)
warning: wrong element type Hash at 0 (expected array)
warning: ignoring wrong elements is deprecated, remove them explicitly
warning: this causes ArgumentError in the next release

The problem is that this method fails in his job:
ie -> if you do define a stub like this:

WebMock::API.stub_request(:post, get_access_token_request).
        with(:body => WebMock::API.hash_including(:code => "test")).

the stub actually responds no matter what the value of :code is (it theory it should only respond when :code == 'test').

bblimke commented Nov 7, 2013

Can you please provide a failing code sample?

steookk commented Nov 8, 2013

I fixed it. I'll submit a pull request tomorrow morning with a better explanation.

trliner commented Nov 11, 2013

@steookk, I'm running into the same issue. What did you do to fix it?

steookk commented Nov 11, 2013

Sorry for the late reply. Here is a better explanation:

  • spec/unit/include_spec.rb does not really work even if tests pass. The main problem is that the resulting @expected var in HashIncludingMatcher is always an empty hash. The second problem is that an empty hash always matches true.
    • this behavior happens because of wrong arguments type passed to Hash[..] at line 7 of hash_including_matcher.rb .
  • This behavior does not happen when you use RSpec::Mocks::ArgumentMatchers#hash_including, which happens automatically most of the times since it has the precedence over WebMock::API#hash_including.
  • I wrote tests in this gist. https://gist.github.com/steookk/7421750 Have a try.
@bblimke bblimke closed this in #332 Nov 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment