bypass
bypass copied to clipboard
Support expectation on exact number of requests
Hi there!
Sometimes I want to set an expectation that my app will call particular endpoint an exact number of times.. I figured I can achieve that by setting some counter and increment it on each request, then assert on its value.. though, I think it would be nice to be able to set that expectation via Bypass.expect functions.. something similar to Mox.expect/4
So in this change I attempted to do exactly that:
Bypass.expect(bypass, 3, fn conn ->
# ...
# Plug.Conn.send_resp(conn, 200, "")
end)
and
Bypass.expect(bypass, "GET", "/foo", 3, fn conn ->
# ...
# Plug.Conn.send_resp(conn, 200, "")
end)
And if that number of requests is not met - it will raise an error:
Expected 3 HTTP request for Bypass at GET /foo, got 5
stacktrace:
(bypass 2.1.0) lib/bypass.ex:122: Bypass.do_verify_expectations/2
...
@bszaf, thank you for the review. I added docs in https://github.com/PSPDFKit-labs/bypass/pull/128/commits/7609e767f215915c3f5e9a4ac09377ba105c302a