-
Notifications
You must be signed in to change notification settings - Fork 19
Description
This is related to issue vonKingsley/hi8.cr#9
Background
HI8 will create two stubs for two consecutive HTTP interactions ("episodes") with identical request signatures.
However, when HI8 starts playing back requests, Webmock will match the second request with the first stub.
Expected Behaviour
- Create stub for e.g. "GET localhost:3000/api", with
response.body == "1" - Create second stub for same request, with
response.body == "2" - On first call, WebMock will dutifully stub the request and return the first response.
- On second call, WebMock will stub the request using the second stub, returning the second response.
Actual Behaviour
- On second call, WebMock matches the request to the first stub, returning the first response.
Possible Solutions
after_request callback
If WebMock.cr had an after_request callback, it might be possible to tell WebMock to remove the first stub after the first request. For that to happen, we could either yield the StubRegistry to the callback, or provide a class getter WebMock.registry for @@registry.
Provide option WebMock.consume_stub(request) and WebMock.consume_after_match? option
We could set a boolean option e.g. WebMock.consume_after_match = true, and in core_ext.cr#L11 add e.g.
stub = if WebMock.consume_after_match?
WebMock.consume_stub(request)
else
WebMock.find_stub(request)
end
Other options might be specifying a numeric TTL per stub indicating how many times it should be used to match a request before it's discarded/consumed.