I have a method that takes block of code as an argument. The problem is: how to test using RSpec if this method called the block?
The block may be evaluated in any scope the method needs, not necessarily using a yield
or block.call
. It be passed to another class, or evaluated it in an anonymous class object or somewhere else. For the test to pass it is enough to evaluate the block somewhere as a result of the method call.
Is there a way to test something like this using RSpec?
See also this for more complex case with lets
and mocks.
I usually do something like
I like using
throw
instead ofraise
for this sort of problem, because it can't be rescued be an arbitrary rescue handler. So it might look like this:Thanks to Dave Newton's suggestion in the comment above I did something like this:
In case of error this prints message:
Which I find informative enough.
Thanks again for help!