Request with WebMock and queries

If you would like to implement a request api stub, you have to consider WebMock first. It is very useful basically. At this time, I got confused about how to send a request with queries as a stub, so I’m going to take a note.

webmock

What if we want to send a request with queries?

For example, it is

https://example.com/pages/1?access_token="abcdefg"

like this.

Even if you write like below,

stub_request(:post, "https://example.com/pages/1?access_token="abcdefg").to_return(status: 200)

it won’t work.

We have to do like this.

stub_request(:post, "https://example.com/pages/1").with(query: hash_including({ 'access_token' => "abcdefg" })).to_return(status: 200)

It will work!

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer at two industry-leading startups ( Go | Ruby | TypeScript | JavaScript | Gin | Echo | Rails | React | Redux | Next)