rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 358 forks source link

Allow multiple receive counts for an expected message #1443

Closed AlbertoTejada closed 2 years ago

AlbertoTejada commented 2 years ago

Allow multiple receive counts matchers for an expected message

Only the last counter matcher in a expectation is considerer, the rest are ignored.

Your environment

Steps to reproduce

Define an expectation with a counter range:

 it 'receives message between 5 and 6 times ' do
   expect(receiver).to receive(:message).at_least(5).at_most(6).times
   method_call
 end

Expected behavior

Expect the case to fail if message is received less than 5 times OR more than 6 times

Actual behavior

The test case fails if message is received more than 6 times, but it passes when message is received less than 5 times

pirj commented 2 years ago

Thanks for reporting. This is a duplicate of #1426 if I'm not mistaken. There are several problems with counts if you check comments, and a suggestion how to improve that. Pull requests are welcome!