Jimmy Soho
2010-Mar-30 03:36 UTC
[rspec-users] describe blocks without before(:all) / after(:all)
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>
David Chelimsky
2010-Mar-30 04:23 UTC
[rspec-users] describe blocks without before(:all) / after(:all)
On Mar 29, 2010, at 10:36 PM, Jimmy Soho wrote:> 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) ?Not in rspec-1, but that''s how rspec-2 works by default. I don''t want to change this in rspec-1 because I don''t plan to release any more major 1.x releases, and this would risk being a compatibility-breaking change. HTH, David> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users