Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
steookk opened this Issue · 4 comments

3 participants

@steookk

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")).
        to_return(......)

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

@bblimke
Owner

Can you please provide a failing code sample?

@steookk

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

@trliner

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

@steookk

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.