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

vishnu pathsny at gmail.com
Thu Jan 20 12:46:52 EST 2011


On Thu, Jan 20, 2011 at 8:49 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
> 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.
>

oops, what I meant was succeeded or failed, not run.

>> 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?


I'm running functional tests (ui driven tests) and whenever a spec has
failed, I'd like to grab a screenshot and save it.


More information about the rspec-users mailing list