class BlahException < Exception; end
class BlahError < StandardError; end
lambda { raise BlahException }.should raise_error(BlahException)
lambda { raise BlahError }.should raise_error(BlahError)
lambda { raise "blah" }.should raise_error(RuntimeError, "blah")
-- Elliot
> raise_error already catches any type of exception, error or not:
>
> class BlahException < Exception; end
> class BlahError < StandardError; end
>
> lambda { raise BlahException }.should raise_error(BlahException)
> lambda { raise BlahError }.should raise_error(BlahError)
> lambda { raise "blah" }.should raise_error(RuntimeError, "blah")
Although it would be unusual to catch non-Error Exceptions in most cases? Most indicate unrecoverable failure; only the SignalException looks like something you might want to catch - I don't know, though. I assume you'd normally register a handler for that.
Ashley
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
Thanks for the response. I think my request was more of a "why call
them errors--in my head one doesn't raise errors--one raises
exceptions and interprets them as errors, so allowing for the syntax
raise_exception would be more mind friendly to me."
> raise_error already catches any type of exception, error or not:Thanks for the response. I think my request was more of a "why call
>
> class BlahException < Exception; end
> class BlahError < StandardError; end
>
> lambda { raise BlahException }.should raise_error(BlahException)
> lambda { raise BlahError }.should raise_error(BlahError)
> lambda { raise "blah" }.should raise_error(RuntimeError, "blah")
them errors--in my head one doesn't raise errors--one raises
exceptions and interprets them as errors, so allowing for the syntax
raise_exception would be more mind friendly to me."
-r
(obviously) I like raise_exception
The only drawback would be that I suppose in keeping with the new name
it "could" be redefined to catch Exception by default, if it currently
catches StandardError(?)
raise_error seems less readable to me, as there is no Error class.
Having both would be fine by me, too.
Happy holidays.
> What I really want to say is "should raise(Blah)" but Ruby already defines(obviously) I like raise_exception
> raise as a keyword :)
>
> I'd be open to aliasing raise_error with raise_exception, renaming it to
> raise_exception and aliasing raise_error for compatibility, but I think this
> might just add confusion rather than clarifying intent. Thoughts?
The only drawback would be that I suppose in keeping with the new name
it "could" be redefined to catch Exception by default, if it currently
catches StandardError(?)
raise_error seems less readable to me, as there is no Error class.
I don't think a deprecation would cause that much of pain, once it is
justified in a changelog. Maybe it would be a change for the next major
version, where people are more willing to accept major changes...
My vote would be to include raise_exception (independently to aliasing
it or not) as the specs turns out more concise when the exception is not
an error.
Best regards and have a great new year!
Rodrigo.
__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/
All righty let the voting begin.
https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/933-add-raise_exception
My current leaning is actually (re a previous comment), to add a new
method raise_exception, which requires them to pass in the
ExceptionClass to be raised, but feel free to discuss this suggestion
at the ticket above.
Hey all - Roger submitted https://rspec.lighthouseapp.com/projects/5645/tickets/933
on this, so if anybody else has more thoughts on it, please add them
to the ticket.
Cheers,
David