You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently testing a method which uses "rescue" like this:
def foo
do_something
rescue Exception => e
log(e) # log the exception and swallow it
end
In one of my specs I want to use "do_not_allow" to confirm that something doesn't happen:
it 'should not call thingy' do
do_not_allow(Target).thingy
foo
end
The trouble is, that if "thingy" is called, RR will immediately throw an RR::Errors::TimesCalledError, which will be swallowed up by the "rescue" in the method being tested and never seen by RSpec.
Would it be possible to change the behavior of "do_not_allow", then, to defer evaluation in the same way that "mock" doesn't actually get verified until the end of the RSpec example?
For the meantime, the workaround is to change my "rescue" handler to explicitly check for RR exceptions and propagate them, but this is a bit ugly because it contaminates the code being tested with knowledge about the testing tools:
rescue Exception => e
raise e if e.kind_of?(RR::Errors::RRError)
log(e) # and swallow
end
Cheers,
Wincent
The text was updated successfully, but these errors were encountered:
I imagine so, because you could throw a very specific symbol which no application will catch "by accident" in the way that we're seeing here (rescuing "Exception" and catching an RR-specific subclass of it).
I'm currently testing a method which uses "rescue" like this:
In one of my specs I want to use "do_not_allow" to confirm that something doesn't happen:
The trouble is, that if "thingy" is called, RR will immediately throw an RR::Errors::TimesCalledError, which will be swallowed up by the "rescue" in the method being tested and never seen by RSpec.
Would it be possible to change the behavior of "do_not_allow", then, to defer evaluation in the same way that "mock" doesn't actually get verified until the end of the RSpec example?
For the meantime, the workaround is to change my "rescue" handler to explicitly check for RR exceptions and propagate them, but this is a bit ugly because it contaminates the code being tested with knowledge about the testing tools:
Cheers,
Wincent
The text was updated successfully, but these errors were encountered: