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
Stub request with hash_including #967
Comments
I found the problem is due to "integer" comparison vs "String" This works. |
I think it makes sense to automatically cast everything to string before doing the Hash diff |
I came across this issue yesterday and it took me a while to debug. After playing around with the Webmock code, I don't think there's a clear solution to fix @bblimke Do you think it would be helpful to add a separate method for this purpose? Something like def query_hash_including(*args)
args = args.map { |arg| arg.is_a?(Hash) ? cast_numeric_hash_values_as_strings(arg) : arg }
hash_including(*args)
end
def cast_numeric_hash_values_as_strings(hash)
hash.transform_values { |value| value.is_a?(Numeric) ? value.to_s : value }
end That might allow Webmock users to use integers, floats, or strings in query param expectations, without breaking anything stub_request(:get, "example.com").with(query: query_hash_including({"a" => "1"})) |
@Bodacious thank you for providing the suggested solution. I wish I feel it's more intuitive to use |
I am trying to match this url
GET http://example.com/?a=1&b=2&x=1
but it fails. Here a reproducible error.
The error says:
The text was updated successfully, but these errors were encountered: