Keep state when a before(:all) hook raises an exception #689

Closed
wants to merge 2 commits into
from

2 participants

@samphippen
RSpec member

Hi,

this is related to #558

I've got the basic functionality working (as illustrated by the test spec in #558).

I'm having trouble getting my spec working. I think @state in the spec provided in this pull request is in the inner scope of the group variable's describe block, and I'm having trouble working out how to get access to it. I've already tried patching a method onto the group instance to get the @state ivar, and the method supplied in the patch which is to use instance_variable_get.

What the spec actually needs to do is get into the @state in the describe block's scope, which I'm not sure how to do.

samphippen added some commits Sep 25, 2012
@samphippen samphippen Add an ensure around store_before_all_ivars in run_before_all_hooks
Signed-off-by: Sam Phippen <samphippen@googlemail.com>
b58128c
@samphippen samphippen Add a broken spec that illustrated what I'm trying to do
Signed-off-by: Sam Phippen <samphippen@googlemail.com>
1b5f590
@myronmarston
RSpec member

Thanks, Sam! I updated the spec, moved it to a place in the spec suite that specifies other before(:all) behaviors and squashed the commits into one:

49370db

One main change to the spec (from what you had) is that we care about the external behavior of rspec (i.e. the fact that ivars are always propogated from before(:all) to after(:all)), not the implementation (e.g. that the logic for this is in run_before_all_hooks)--so I changed the spec to run the entire example group rather than coupling it to the helper method that was the source of the bug.

@samphippen
RSpec member

Cheers Myron. My head exploded slightly at the meta-ness of testing your tests with some tests......

@myronmarston
RSpec member

Cheers Myron. My head exploded slightly at the meta-ness of testing your tests with some tests......

Haha, yeah, it's a little mind-expanding at first to see how rspec specs rspec :).

Anyhow, one of the basic techniques I used here (that I find comes in handy over and over again) is using the fact that blocks are closures to declare a local variable all the blocks have access to, so I could set the value of the variable in the after hook. Did you follow how that worked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment