[rspec-users] detecting status of a spec in after block

David Chelimsky dchelimsky at gmail.com
Thu Jan 20 10:19:04 EST 2011

On Jan 20, 2011, at 8:17 AM, vishnu wrote:

> Hi
>   inside an after :each block, whats the best way to find out if the
> current spec has run?

If you're in an after block, the current spec has run. No need to query anything.

> Right now the only solution I have is
> self.example.instance_variable_get(:@exception).nil?. Is there a
> better solution?

There is not. There is example.metadata[:execution_result], but it doesn't get the exception until after the afters (in case one has an exception).

What is it you're trying to do?

> Also, is there an on_error hook I can use instead of an after :each block?

That's an interesting idea, but again, what are you trying to accomplish?


More information about the rspec-users mailing list