Closed moroshko closed 9 years ago
The .willRespondWith()
is required to be set to stub out the response, and to allow us verify (on the provider side) that the real response matches the actual response. If you took that out, the test would fail, because the client code would have no body to parse.
The expectation in success
asserts that your consumer code has correctly handled the response.
Imagine a more complicated example where the document was parsed to a domain model that did not exactly correspond with the JSON, and it will make more sense.
Thanks, makes sense now
Looking at this example, I wonder what is the point of specifying the
body
in.willRespondWith()
?Looks like the body is verified in the
success
function, and if this line is removed, the test passes (so thebody
that is specified in.willRespondWith()
is basically ignored).In other words, looks like I need to duplicate the expected response in 2 places:
body
in.willRespondWith()
expect
insuccess()
Is there a way to avoid the duplication?