Topic: Using same stubs in multiple spec methods.

Hi

Why stub objects cannot be reused in two methods below?

require File.dirname(__FILE__) + '/../spec_helper'

module MySpecHelper
  def get_foo
    return stub("foo", :do_foo => true)
  end
end

describe "foo" do
  include MySpecHelper
 
  before(:all) do # Before :all leads to failure here, but before :each works. Why?
    @foo = get_foo
  end
 
  it "should work" do
    @foo.do_foo.should == true
  end

  it "should work again" do
    @foo.do_foo.should == true
  end
end


In most cases, before(:each) works well, but hypothetically one might need a large structure with stubs that would be expensive to initialize every time.

Best regards
--
Yar

Re: Using same stubs in multiple spec methods.

Why are you using before(:all) anyway? You know before(:each) works in exactly the same way.