I am trying to use RSpec mock and should_receive
in custom matcher. I want to catch the error caused by the should_receive
to return proper value from the matcher and cause it output my custom failure message.
How to do it? Or maybe I should change my approach?
The answer is:
match do |obj|
# do some setup and mocks here
begin
RSpec::Mocks::verify # run mock verifications
true
rescue RSpec::Mocks::MockExpectationError => e
# here one can use #{e} to construct an error message
false
end
end
Finally found it here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With