Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find out if URL was requested #81

Open
pimnijman opened this issue Jul 16, 2017 · 0 comments
Open

Find out if URL was requested #81

pimnijman opened this issue Jul 16, 2017 · 0 comments

Comments

@pimnijman
Copy link

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant