Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Missing #prepend_before and friends from rspec 1 #126

Closed
jasonroelofs opened this Issue · 8 comments

2 participants

@jasonroelofs

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
Owner

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?

@jasonroelofs

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
Owner

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.

@jasonroelofs

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
Owner

"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.

@jasonroelofs

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 dchelimsky reopened this
@dchelimsky
Owner

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
Owner

Closed by #579.

@dchelimsky dchelimsky closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.