[rspec-users] How can I use nested "before" functions?
erik.helin at gmail.com
Fri Dec 3 21:11:15 EST 2010
On Fri, Dec 3, 2010 at 16:43, Matt Wynne <matt at mattwynne.net> wrote:
> On 1 Dec 2010, at 05:47, helino wrote:
> > Hi everyone,
> > I've started learning Ruby and RSpec, and I've ran into a small
> > problem. I have one "before" functions which run before all my
> > descriptions and the context in the spec, and then I have another
> > "before" function inside a context, which is set to run once before
> > all the "it" inside that context.
> > My problems is that the outer "before" does not run prior to the
> > "before" inside my context. This creates an error, since the "before"
> > inside the context relies on a variable being created in the outmost
> > "before".
> > Is this how it is supposed to be, or am I doing something wrong?
> > Gists:
> > * "rspec spec --backtrace" output: https://gist.github.com/723021
> > * router.rb: https://gist.github.com/723020
> > * router_spec.rb: https://gist.github.com/723015
> You're getting before(:each) and before(:all) mixed up.
> before(:each) is the default. You really don't want to use before(:all) in
> anything but exceptional circumstances. Right now you have a mix of the two,
> which I think it why you're getting the suprising behaviour.
I know that I'm mixing before(:each) and before(:all). What I'm wondering is
the rules for how they interact? Are then any "scoping" rules in RSpec? I
think that it makes sense that a before(:all) defined in a context on which
a before(:each) is already applied gets run after the before(:each) has run,
but that's just my opinion.
> > I'm using Ruby version 1.9.2p0 with rvm on Mac OS X 10.6.5 and RSpec
> > 2.1.0.
> > Thanks for a wonderful framework!
> > Best regards,
> > Erik
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> matt at mattwynne.net
> 07974 430184
> rspec-users mailing list
> rspec-users at rubyforge.org
Thanks for your answer!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users