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

John Kolokotronis johnjkle at gmail.com
Wed Feb 4 12:55:07 EST 2009

> Why do you want before(:all)?  Generally it's use is disregarded, just
> as global variables are considered harmful, not because they can't be
> used well, but because 99% of the times they aren't.

Because I want to be able to create a single @browser object at the
of my tests and have it passed to all examples. Without nested
examples, that
works just fine - I can create my browser instance in the before(:all)
block and
avoid using a global variable. In nested examples, I don't see a good
way to
do that - I could always set up the browser instance as a global (did
that in
the past with Test::Unit and many Watir users do so) but I'd like to
avoid this.

If I didn't use a before(:all) block or a global variable, would there
be any way to
pass my browser object to all example groups?

Currently my tests look like this:

describe "A series of tests" do
  before(:all) do
    @browser = Watir::Browser.new

  it "Test 1: it should go to www.google.com" do

Obviously, been able to use nested describe groups would make the
tests easier
to read for non-coders here and that's why I wanted to use them...



More information about the rspec-users mailing list