-
Notifications
You must be signed in to change notification settings - Fork 556
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
hash_including not working at all? Doesn't find any query #371
Comments
Try it with keys being strings not symbols. |
@bblimke I think I've found the issue and it's quite stupid: it "receive a request when mocked with query param", focus: true do
stub_request(
:get,
dummy_url
).with(
query: hash_including({
param1: '5',
param2: 'random2'
})
).to_return(
body: 'body 1'
)
expect(
HTTParty.get(dummy_url, {
query: {
param1: 5,
param2: 'random1'
}
}).body
).to eq 'body 1'
end The keys are not required to be strings. But the values must be strings. |
@Fire-Dragon-DoL Thanks for the tip, this issue was killing me today! |
@dzajic Happy to help you ;) |
Since query values can only be strings, it indeed makes sense to autoconvert values to strings for comparison. |
@Fire-Dragon-DoL if you like I can try and help you with a fix. I'm new to codebase too, but 2 eyes might help. |
I hit this today as well. @presidentJFK or @Fire-Dragon-DoL, have either of you started on a patch? |
@Fire-Dragon-DoL @zdennis I have opened a Pull Request #517 trying to fix this problem. If you could take a look and see if it fixes your problem. Maybe try the branch against your failing tests. |
@presidentJFK seems good, one point though, maybe you want to stringify hash keys too? |
@Fire-Dragon-DoL WebMock already converts keys to strings, I added a spec exercising this functionality on #517 |
This was driving me nuts too, thanks @Fire-Dragon-DoL 🙌 |
I wrote a test after finding out that my stubbed requests were not called correctly, here is a test code:
Both of them are not passing, they do not receive the request.
Notice that if I use do end block in
with
, I do manage to receive the request so it's definitely hash_including the issue, expecially because if I remove it, the query matching works fine (if I addparam2: 'random1'
).The text was updated successfully, but these errors were encountered: