Re: [rspec] Raising a mocked exception

2018-04-11 Thread Myron Marston
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 `' As such, there’s no

Re: [rspec] Raising a mocked exception

2018-04-11 Thread Myron Marston
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

Re: [rspec] Raising a mocked exception

2018-04-11 Thread David Shockley
Thanks for the excellent and informative reply. I'll have to think about that :) On 11 April 2018 at 13:58, Myron Marston wrote: > In general, I recommend that you don't use test doubles in place of value > objects, and generally exception types are value objects.

[rspec] Raising a mocked exception

2018-04-11 Thread Asher Shockley
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/008ea9122e62b051b3614d07a36fae23 Thanks -- You received this message because you are subscribed to the Google Groups "rspec" group. To

Re: [rspec] Raising a mocked exception

2018-04-11 Thread David Shockley
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