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

Proposal for callback for matcher #89

Open
icanswiftabit opened this issue Oct 25, 2017 · 1 comment
Open

Proposal for callback for matcher #89

icanswiftabit opened this issue Oct 25, 2017 · 1 comment

Comments

@icanswiftabit
Copy link

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 ?

@kylef
Copy link
Owner

kylef commented Oct 4, 2021

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

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

2 participants