-
Notifications
You must be signed in to change notification settings - Fork 555
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
Add RequestStub helper methods for accessing request signatures #574
base: master
Are you sure you want to change the base?
Add RequestStub helper methods for accessing request signatures #574
Conversation
@twolfson thank you for submitting this pull request and for an attempt to improve the previous solution. Unfortunately your solutions still has the same problems as the previous one. First of all There are two problems with your solution, that I mentioned already in the previous pull requests are:
now if you ask or another example:
|
I agree that With respect to your counter examples, these are currently issues as well with the When we add a
I believe that in expected usage scenarios these edge cases don't come up. People will likely only set up stubs once per With respect to |
Yes, people usually set only one stub per example - usually. The code needs to be deterministic though. You are right that times matcher has exactly the same issue if you use The problem is not with how it works, but how it reads though. Initially you had to write:
to avoid duplication in declaring request signatures, support for matching directly on request stub was added:
Therefore I agree it's confusing and it's worth considering changing the WebMock API to make it clear.
Perhaps we could add a method to WebMock's API. i.e. something like in above examples |
Ah, I see. Thanks for clarifying -- I think introducing Another solution seems to be using the https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/request_stub.rb#L7 expect(stub1.request_pattern).to(have_been_requested.once())
puts executed_requests(stub1.request_pattern) Or maybe we rename |
In #544 @brettlangdon submitted a proposal to add
requests
toRequestStub
instances. It was declined for legitimate concerns of overlapping requests. We have naively been using the forked version in our own repo, finally ran into the issue, and found a way to solve the concerns.We have added a new test to guarantee separate request signatures are not combined via
matches?
(i.e. "should not combine identical requests").This solution is more/less the same as our #544 (use the same approach as
times(n)
matcher) but instead of losing request ordering and cardinality by storing request counts on ahash
. We moved to storing request signatures on an array.I'm pretty confident we have no overlap issues now since any issues would mean that
times(n)
has those same issues.In this PR:
requests
,first_request
, andlast_request
to request stubsHashCounter
Notes:
The initial revision of this PR is more of a proposal than a final product. There need to be some things that will be changed if accepted (e.g. rename
HashCounter
). But the concepts are here.Reference code used from
times(n)
:https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/rspec/matchers/request_pattern_matcher.rb#L18-L21
https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/request_execution_verifier.rb#L15-L18
https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/request_registry.rb#L16-L20
https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/util/hash_counter.rb#L6-L18
https://github.com/bblimke/webmock/blob/v1.22.6/lib/webmock/http_lib_adapters/net_http.rb#L75-L77