webmock icon indicating copy to clipboard operation
webmock copied to clipboard

Ignore JSON keys order when stubbing a request

Open maxdidato opened this issue 11 years ago • 4 comments

When stubbing a request with a json body, the actual request has to have the exact same string representation of json in order to work. So, for example

stub_request(:post,'www.example.com').with(body: {key1: 'value1,key2: 'value2'}.to_json) 

will not be matched by

POST www.example.com 
"
 {
   "key2" : "value2",
   "key1" : "value1"
 }
"

Would be better to parse both JSON (request and stub_request) in hashes and make the comparison ignoring the keys order.

maxdidato avatar Jun 10 '15 09:06 maxdidato

I have noticed the same things just now. Including what @maxdidato is suggesting would be nice. :+1:

jonathanpa avatar Jun 19 '15 08:06 jonathanpa

Any update on that? I would be happy to provide a solution if the issue makes any sense.

maxdidato avatar Jun 29 '15 13:06 maxdidato

+1

uchoaaa avatar Sep 23 '15 20:09 uchoaaa

this is coming up next on my list, need to fix some code around the same area first, and then tackle this.

davidbegin avatar Sep 23 '15 22:09 davidbegin