You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to know whether my stubbed URL is requested.
I imagine this could work something like this:
let body = [ "description": "Kyle" ]
let userStub = stub(http(.PUT, uri: "/kylef/Mockingjay"), json(body))
expect(userStub.requested).toEventually(beTrue())
Since this doesn't work, I came up with a solution using a custom matcher:
/// Creates a custom matcher that calls the requestMatchedHandler when a request was succesfully matched
func matcher(_ method: HTTPMethod, uri: String, requestMatchedHandler: @escaping () -> Void) -> (_ request: URLRequest) -> Bool {
let matcher = http(method, uri: uri)
return { (request: URLRequest) in
let result = matcher(request)
if result {
requestMatchedHandler()
}
return result
}
}
var requestMatched = true
let body = [ "description": "Kyle" ]
stub(http(.PUT, uri: "/kylef/Mockingjay", requestMatchedHandler: { () in
requestMatched = true
}), json(body))
expect(requestMatched).toEventually(beTrue())
Reacted by Leo Giertz, Davis Koh, Hugal31, Pavel Zorin and Pavel Sorokin
Activity