1

I wold like to test whether a request contained some inner value in json. Let assume the request body is:

  level1: {
    level2a: "value1",
    level2b: "value2",
    ...
  },
  ...
}
      

Then I have the following code:

 WebMock.stub_request(:post, "http://127.0.0.1:/path")
        .with(body: hash_including({level1: {level2a: 'value1'}}))
        .to_return(status: 200, body: '{}', headers: {})

The code above does not work unfortunately. I've been hoping it'll work with matching only sub-set of json.

According to the doc: Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys. I am not sure if it works the way I want.

The request is too big here though for quoting it all.

Any ideas for why the test is not working and how to fix or rewrite it?

paliwodar
  • 81
  • 6

0 Answers0