PSPDFKit-labs / bypass

Bypass provides a quick way to create a custom plug that can be put in place instead of an actual HTTP server to return prebaked responses to client requests.
https://hex.pm/packages/bypass
MIT License
964 stars 111 forks source link

Pipe expectations #103

Open thiamsantos opened 4 years ago

thiamsantos commented 4 years ago

Motivation

Would be nice to be able to pipe expectation calls, passing the bypass instance to next expectation.

bypass
|> Bypass.expect("POST", "/auth", fn conn ->
  # response ...
end)
|> Bypass.expect("POST", "/resource", fn conn ->
  # assert authenticated
  # response
end)

Similar to what mox does:

MyMock
|> expect(:add, fn x, y -> x + y end)
|> expect(:add, fn x, y -> x * y end)

Proposed solution

Return the bypass instance back in all expectation functions.