Skip to content

Find out if URL was requested #81

Open

Description

@pimnijman

Feature request:

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())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions