Thanks for the excellent and informative reply. I'll have to think about that :)
On 11 April 2018 at 13:58, Myron Marston <myron.mars...@gmail.com> wrote: > In general, I recommend that you don't use test doubles in place of value > objects, and generally exception types are value objects. (That is, they > carry data, but don't have any meaningful behavior and certainly shouldn't > perform any I/O). Given that, I don't understand why you'd want to use a > test double in place of an exception. > > The fact that you find yourself wanting to is probably communicating > something about your design, and you may want to take a step back to think > through why you're trying to use a double in place of an exception. > There's likely an alternate design that will work better. > > HTH, > Myron > > On Wed, Apr 11, 2018 at 1:34 PM, David Shockley <daemon.shock...@gmail.com > > wrote: > >> 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/ms >>> gid/rspec/CADUxQmv5n_2fYTHRtQpy9%3Dxeom1Cj8Mb4kUS7kQsx-a%3DM >>> 01hEA%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/ms >> gid/rspec/CACp6SzUuvsS23SRw%2Bgwws3jiTCv-NazBOa3NJGyKBvNt8FV >> 1_g%40mail.gmail.com >> <https://groups.google.com/d/msgid/rspec/CACp6SzUuvsS23SRw%2Bgwws3jiTCv-NazBOa3NJGyKBvNt8FV1_g%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/CADUxQmtYGyYV8CM6Vki0roDdUYkHK38H2EjkN%3DJ0kkbdjAmrnA% > 40mail.gmail.com > <https://groups.google.com/d/msgid/rspec/CADUxQmtYGyYV8CM6Vki0roDdUYkHK38H2EjkN%3DJ0kkbdjAmrnA%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/CACp6SzWpPz0WdSrSq1dwDeT9sfZkHhOG0o90Zp7VSBTWcuapAg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.