rspec-mocks: 'receive' matcher doesn't support custom failure messages
Subject of the issue
rspec-expectations supports the passing of customized failure messages to the #to method:
expect(array).to be_empty, "expected empty array, got #{array.inspect}"
The documentation states that
This works for any matcher other than the operator matchers.
This does not work for the receive matcher, however, and there’s no mention of it in the rspec-mocks documentation.
Your environment
- Ruby version: 2.4.4
- rspec-mocks version: 3.8.0
Steps to reproduce
RSpec.describe RSpec do
# rspec outputs this custom failure message
it 'supports custom failure messages for base matchers' do
expect(1).to eq(2), 'something went wrong!'
end
# rspec does NOT output this custom failure message
it 'supports custom failure messages for rspec-mocks matchers' do
expect(RSpec).to receive(:describe), 'something went wrong!'
end
end
Expected behavior
I expect the second example to output the custom message, "something went wrong!"
Actual behavior
The default failure message is output instead:
(RSpec).describe(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 21 (17 by maintainers)
Here it is https://relishapp.com/rspec-staging/rspec-mocks/docs/basics/expecting-messages
Hello
I did some pairing this morning with @nicoolas25 on this issue. We wrote draft patchs:
With:
It produces:
Is something like that you were thinking @JonRowe in https://github.com/rspec/rspec-mocks/issues/1250#issuecomment-453199176?
We try to do minimal changes but the result in https://github.com/rspec/rspec-expectations/pull/1156 looks maybe a little bit “hacky”.
Thanks in advance for the review. I will add tests when the idea will be validated.