[rspec-users] How can I use nested "before" functions?

helino erik.helin at gmail.com
Wed Dec 1 00:47:50 EST 2010


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

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


More information about the rspec-users mailing list