class Foo def call Bar.new.call endend
class Bar def call Meep.new.call endend
class Meep def call "no error" rescue ArgumentError "error" endend
allow_any_instance_of(Meep).to receive(:call).and_raise(ArgumentError)expect(Foo.new.call).to eq "error"
Hi Carlos,
It’s not clear to me what you’re trying to accomplish with that example. Meep#call has a rescue clause but the code being rescued involves no method calls ("no error" is not a method call) and, barring something truly bizarre like a busted ruby installation, cannot raise any sort of exception. As there’s no possibility of an ArgumentError being raised, there’s no point in rescuing it (or in trying to write a test to cover the possibility of an exception being raised).
In addition, allow_any_instance_of(Meep).to receive(:call).and_raise(ArgumentError) completely replaces your existing implementation of Meep#call including the rescue ArgumentError.
I’m not sure what to suggest since your example doesn’t make sense to me.
Myron
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/9a05e52f-21c5-49bf-808b-e826261f9936%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/9a05e52f-21c5-49bf-808b-e826261f9936%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/CADUxQmuwGYSNOU8uQsVLT9waGCkcQK8mZ7Nb_RPzv-iihKLTSg%40mail.gmail.com.