Skip to content

Need to "consume" stub after first matched request #20

@aisrael

Description

@aisrael

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

  1. Create stub for e.g. "GET localhost:3000/api", with response.body == "1"
  2. Create second stub for same request, with response.body == "2"
  3. On first call, WebMock will dutifully stub the request and return the first response.
  4. On second call, WebMock will stub the request using the second stub, returning the second response.

Actual Behaviour

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions