[rspec-users] [Rspec] How do you nest before(:all) or after(:all) blocks?

John Kolokotronis
Wed, 04 Feb 2009 15:07:48 -0000

Thanks for the reply David - much appreciated. At least now I know
that it can''t be done, rather
than pursuing it further for now. I''ll just have to live without that
functionality for now and add
it later on if a fix is made available.

Regards,

John

On Feb 4, 2:03?pm, David Chelimsky <dchelim... at gmail.com>
wrote:
> On Wed, Feb 4, 2009 at 3:07 AM, John Kolokotronis <johnj... at
gmail.com> wrote:
> > Hi all,
>
> > I''m new to Rspec but loving it so far and looking to use it
as a
> > replacement for a Test::Unit framework I have which drives a web app
> > via Watir. So far, things have worked very well with Rspec but I
can''t
> > get my head around how before/after(:all) blocks would work in nested
> > groups, or even if what I am doing is possible.
>
> > What I want to do is something like this:
>
> > describe "This is a set of tests: " do
> > ? ? ? ?before(:all) do
> > ? ? ? ? ? ? ? ?puts "this should only appear once"
> > ? ? ? ?end
>
> > ? ? ? ?describe "Test 1" do
> > ? ? ? ? ? ? ? ?puts "test 1"
> > ? ? ? ?end
>
> > ? ? ? ?describe "Test 2" do
> > ? ? ? ? ? ? ? ?puts "test 2"
> > ? ? ? ?end
> > end
>
> > Expecting the before(:all) block to run only once and see something
> > like:
>
> > - this should only appear once
> > - test 1
> > - test 2
>
> > but what I am getting is:
>
> > - this should only appear once
> > - test 1
> > - this should only appear once
> > - test 2
>
> > So my question is, how can you add before/after(:all) blocks that run
> > once and only once for for all examples, if all the examples are
> > nested in one main describe block? Is that something that''s
even
> > possible? I''d appreciate any pointers anyone may have.
Thanks!
>
> Right now it''s not possible. There''s an open ticket on
this:
>
> http://rspec.lighthouseapp.com/projects/5645/tickets/632
>
>
>
> > Regards,
>
> > John
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at
rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users