Mockingjay
Mockingjay copied to clipboard
Proposal for callback for matcher
I was thinking what would help me in testing. Callback when stub responds to request. I am more than happy to implement it. What do you think @kylef ?
Both the matcher and builder are already callbacks, you are free to put whatever logic you want in those places. The "builder" is invoked when the stub is matched.
stub(http(.post, uri: "https://example.com/authorisations")) { request in
XCTAssertEqual(request.allHTTPHeaderFields?["Authorization"], "Bearer abc123")
XCTAssertEqual(request.allHTTPHeaderFields?["Content-Type"], "application/json")
if denied {
return json(["token": "newtokenabc"])(request)
}
denied = true
return problem(code: 403, title: "Access Denied")(request)
}