Cool. That makes sense. My current work around is to use:

allow_any_instance_of(Exception).to
receive(:my_custom_method_ive_added_to_exception).and_raise

Is there a better solution? Do you think it's possible to write an
exception_double and exception_spy methods that build subclasses of
Exception that support the double/spy methods directly, or is that
unfeasible / a bad idea?



On 11 April 2018 at 13:01, Myron Marston <myron.mars...@gmail.com> wrote:

> Ruby requires that any object passed to raise must be an exception class
> or object:
>
> 2.4.3 :001 > raise Object.newTypeError: exception class/object expected
>         from (irb):1:in `raise'
>         from (irb):1
>         from /Users/myron/.rvm/rubies/ruby-2.4.3/bin/irb:11:in `<main>'
>
> As such, there’s no way to RSpec to be able to raise an arbitrary object.
>
> Myron
> ​
>
> On Wed, Apr 11, 2018 at 12:43 PM, Asher Shockley <
> daemon.shock...@gmail.com> wrote:
>
>> Is it possible to have a mocked method raise a mocked object instead of a
>> real instance of Exception?
>>
>> https://gist.github.com/david-shockley-beeline/008ea9122e62b
>> 051b3614d07a36fae23
>>
>> Thanks
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To post to this group, send email to rspec@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/rspec/76d123cf-1fe0-4d88-b0fd-47a856253c22%40googlegroups.com
>> <https://groups.google.com/d/msgid/rspec/76d123cf-1fe0-4d88-b0fd-47a856253c22%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to rspec@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/rspec/CADUxQmv5n_2fYTHRtQpy9%3Dxeom1Cj8Mb4kUS7kQsx-a%
> 3DM01hEA%40mail.gmail.com
> <https://groups.google.com/d/msgid/rspec/CADUxQmv5n_2fYTHRtQpy9%3Dxeom1Cj8Mb4kUS7kQsx-a%3DM01hEA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> 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+unsubscr...@googlegroups.com.
To post to this group, send email to rspec@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CACp6SzUuvsS23SRw%2Bgwws3jiTCv-NazBOa3NJGyKBvNt8FV1_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to