Missing #prepend_before and friends from rspec 1 #126

jasonroelofs opened this Issue Aug 27, 2010 · 8 comments


None yet
2 participants

Not sure if this is simply not yet implemented or there is a new way of doing this that I haven't been able to figure out, but I need to be able to specify that a before block needs to be run first for every test. Right now putting config.before(:each) {} puts the before block as the last one run before the actual spec.


dchelimsky commented Aug 27, 2010

Not yet implemented, but I had planned to not implement it because it adds a lot of complexity for a rare use case for which there are likely other, simpler, solutions.

Can you describe the use case for me?

My library is a code generator and I need to make sure to clear out the results of previous tests before anything happens for the next test.

Thinking about it another way, I could use an after(:each) block though that means I'd have to turn that off if I needed to inspect the results of the test after a failure.

How much work would it be to simply have the config.before(:each) be added to the chain first (and after added to the chain last) instead of last?


dchelimsky commented Aug 27, 2010

It's not just about the effort/complexity of the code. It's about the simplicity of the feature. It's much easier to understand that a block is added to the end of the befores or to the beginning of the afters as they are encountered.

This sounds like a reasonable use case though, so I'll add keep it on the list. May rethink the API a bit, but we'll support it somehow.

I guess I would argue then that the current implementation is counter-intuitive. I initially assumed that config.before(:each) is the first before block hit for every test, instead of the last, it being outside of the test and something that you are "configuring" rspec to take into account before you ever define your test cases.

Maybe I'm alone in that idea, I'm not sure what other people's expectation are or have been.


dchelimsky commented Aug 27, 2010

"I initially assumed that config.before(:each) is the first before block hit for every test"

That is the expected behaviour, so if you're seeing something then there is a bug. If so, please change the name of the issue to something like "config.before(:each)" is run last.

BAH. I'm sorry, this is me not comprehending the code that I wrote... I'm using a mix of before(:each) and before(:all) and was expecting config.before(:each) to run before a before(:all) definition, which doesn't really make sense. rspec is working as expected, I apologize for the non issue.

dchelimsky reopened this Jan 17, 2012


dchelimsky commented Jan 17, 2012

I'm reopening this even though @jameskilton's issue was resolved differently. Reinstating prepend_before would solve an issue in rspec-rails. Docs should state that the intended use is for extension libraries, not end-user apps.


dchelimsky commented Mar 18, 2012

Closed by #579.

dchelimsky closed this Mar 18, 2012

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