[rspec-users] describe blocks without before(:all) / after(:all)

Jimmy Soho jimmy.soho at gmail.com
Mon Mar 29 23:36:55 EDT 2010


Hi All,

We have many specs like the pattern given below.

The problem is that it's slow, because each inner context block will execute
the before(:all) in the outer describe block.

Is there a way to setup an inner context block that does not execute the
before(:all) and after(:all), but does execute the before(:each) and
after(:each) ?

Based on some playing around (removing inner context blocks) we think this
would speed up our tests by a factor of 10.


Cheers,
Jimmy

-----

describe Project do
  before(:all) do
    # statements that set up an object graph, relatively slow
  end

  after(:all) do
    # tear down object graph
  end

  it { should ... }
  it { should ... }
  it { should ... }
  it { should ... }

  context "target calculations" do
    before(:each) do
      # non-expensive statements, just setting up for example the subject,
Time.zone, locale, etc.
    end

    it { should ... }
    it { should ... }
    it { should ... }
  end

  context "duration calculations" do
    before(:each) do
      # non-expensive statements
    end

    it { should ... }
    it { should ... }
    it { should ... }
  end

  context ...
  context ...
  [ etc. ]

end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100330/236a93b2/attachment.html>


More information about the rspec-users mailing list