I wrote a test after finding out that my stubbed requests were not called correctly, here is a test code:
require 'spec_helper'
describe WebMock, focus: true do
let!(:dummy_url) { 'http://dummyurl.com' }
it "receive a request when mocked with query param on a regex" do
stub_request(
:get,
/#{ dummy_url }/
).with(
query: hash_including({
param1: 5
})
).to_return(
body: 'body 1'
)
expect(
HTTParty.get(dummy_url, {
query: {
param1: 5,
param2: 'random1'
}
}).body
).to eq 'body 1'
end
it "receive a request when mocked with query param without a regex" do
stub_request(
:get,
dummy_url
).with(
query: hash_including({
param1: 5
})
).to_return(
body: 'body 1'
)
expect(
HTTParty.get(dummy_url, {
query: {
param1: 5,
param2: 'random1'
}
}).body
).to eq 'body 1'
end
end
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 add param2: 'random1').
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').