New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to do hash_excluding matching? #443
Comments
For now there's this workaround for module BodyPatternExtensions
def matches?(body, content_type = "")
if @pattern.instance_of?(RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher)
@pattern === body_as_hash(body, content_type)
else
super
end
end
end
module WebMock
class BodyPattern
prepend BodyPatternExtensions
end
end |
@x-yuri There is no way to do it, unless you use custom matching block. Nice workaround though. The proper solution would require adding Perhaps it's worth adding a change to WebMock and allow it to accept any kind of RSpec::Mocks::ArgumentMatchers::* matcher. |
By custom matching block you must be meaning this: stub_request(:post, 'http://example.com/path')
.with { |request| hash_excluding(a: '1') === Rack::Utils.parse_nested_query(request.body) } Which brings the question, if I can call
But there are not only hash matchers there. How will you know what to pass to any one of them? |
👍 This is a pain for places where you want to ensure that a given header is not present, since webmock will match any superset of the expected values. (i.e. trying to do the opposite case from #276) |
Ran into this issue today - guessing it's still awaiting a PR, as it hit me too, returning a
(mostly leaving this comment to add to the google-ability of this line to get to this issue) Will try the workaround for now... and sadly it doesn't seem to work - the above issue still gets triggered. Guess the monkey patch above is a few years old now :) |
In a similar situation where I'm trying to ensure the abscence of a certain header, rather than its presence - not seeing a nice way to go about it. |
I was facing a similar issue I opened this Pull Request as a suggestion to fix this issue: webmock/lib/webmock/request_pattern.rb Line 286 in 833291d
|
Like so:
rspec
has this matcher, but it doesn't seem to work forwebmock
.The text was updated successfully, but these errors were encountered: