-
Notifications
You must be signed in to change notification settings - Fork 0
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
Impossible to check that method is executed in a range times. #63
Comments
I couldn't find this apart from What I would suggest:
We can only afford 2 & 3 in a major version, but as we're nearing 4.0, it's possible to do so in I'd suggest taking a look at https://github.com/rspec/rspec-expectations/blob/43bf64b01f8356979ffbc373b2e81d2ab1389b29/lib/rspec/matchers/built_in/count_expectation.rb#L103 for inspiration. Would you like to hack on it? |
Is it acceptable to have 2+3+add method .in_range(from..to)? |
Something like expect(tmp).to receive(:call).and_return(nil).in_range(1..2).times ? 🤔 |
Yes, something like it. |
Shortly: no. The introduction of this new method is orthogonal to the fixes, and can be done separately. |
There's one more issue I could spot: r = double
expect(r).to receive(:foo).at_most(:once).and_return(1, 2)
r.foo
r.foo surprisingly, this passes. |
This way it works for me to test how many times method is called: allow_any_instance_of(ClassName).to receive(:your_method)
allow(ClassName).to receive(:find).and_return(your_instance) # if you need to test #update action
put your_route_url(your_instance, subdomain: 'your_subdomain', host: '127.0.0.1.xip.io', type: 'your_type'), params: params # if you need to test #update action
expect(your_instance).to have_received(:your_method).once |
Subject of the issue
According to the documentation methods, at_least and at_most can be chained to have range check: method is called between N and M times. (at least N times and not more then M times).
But rspec-mocks actually checks the last condition and ignores previous ones.
Your environment
Steps to reproduce
Expected behavior
Both tests should fail since one of the conditions is not followed.
Actual behavior
Both tests pass since the condition, which is at the end, overwrites the previous one.
The text was updated successfully, but these errors were encountered: