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
An unmade request can cause tests with stubs to spuriously pass #179
Comments
@jkakar - interesting. I'll have to give this further thought in the general case, for now a couple work arounds come to mind. You could set variables inside the excon request (outside of the stubs) and then check these. I do this, for instance, in heroku.rb as a way of tracking that you have made an app (for instance) so that subsequent dependent calls can look that app up. In this case you could simply set a class/global in the before, change it in the stub and check/reset it in the after. Similarly you could have a counter that incremented (instead of a boolean or something) so you could specify that it had been called a certain number of times. Anyway, this still isn't easy to access/use but at least it would allow it. I'll give the more general case/usage additional thought... |
I wonder if pop/deleting the stub should be the normal behavior. Since they exist as an array, you could always just add the same stub multiple times if needed. Then you could more explicitly ask if a particular stub still existed instead of just checking for empty also. What do you think? |
The main thing is that when I stub a call I expect it to be invoked. So yeah, popping stubbed calls when they're invoked and expecting the |
I did add #unstub I believe. So you could pass the params given inside a stub to unstub to have something remove itself, which is at least a step forward (albeit not a default). How should verify work? I'm not sure checking for an empty stub list is really correct. Maybe you could just check |
I think |
Fair. I guess my concern was not well explained. Since stubs are global, if you are using something else which ships with excon mocks as part of your testing, you may not want to clear things out (lest you break the provided mocks). This may go back to an earlier ideas, providing namespaces for stubs (by default they would work the same, but people that ship mocks could namespace it to their gem to avoid this issue). |
Ah, right, I could see that. But even then, if you're using something |
This issue has been automatically marked stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing as duplicate of #434. |
I'm using the stub functionality built in to Excon and I really like
it. Having this functionality be a first-class citizen is super
awesome, especially in this kind of library. One small issue I have
is that, in some cases, tests can spuriously pass if an expected
request is not made.
For example, consider this application code that might represent a
client library that makes fire-and-forget calls to an API:
And the accompanying test logic:
I expect this test to fail if the code in
make_request
is commentedout completely, but it doesn't. The
Excon.stub
block simply nevergets called. My workaround, for now, is to add an
Excon.stubs.pop
call to the test:
And then, in
teardown
, ensure that all stubs have been consumed:This is okay, but it's also error-prone because I may forget a call to
Excon.stubs.pop
and I also have to be careful to pop from the frontof the
Excon.stubs
array and not the end because of the way it worksinternally. It'd be nice if there was a method to confirm that all
expected requests were made, something like:
The text was updated successfully, but these errors were encountered: