[rspec-users] nested blocks

Chris Hoffman chris.c.hoffman at gmail.com
Tue May 15 14:00:32 EDT 2007


Hello,

Does anyone have an explanation for why the following code results in
the error that follows?  I also would value any criticisms of my
approach (i.e., defining it_should_populate_collections).  Thanks

-Chris

#Code

def it_should_populate_collections(condition=nil)
  it "should populate any necessary collections #{condition}" do
    [*@collections_to_populate].each do |collection|
      collection_model = collection.to_s.classify.constantize
      collection_model.should_receive(:find).with(:all).and_return("the
#{collection}")
    end
    yield
    [*@collections_to_populate].each do |collection|
      assigns[collection].should == "the #{collection}"
    end
  end
end

describe "Foo" do
  before(:all) do
    @collections_to_populate = :bars
  end

  before(:each) do
    @obj = Foo.new
  end

  it_should_populate_collections "on a save failure" do
    @obj.should_receive(:save)
    post @action
  end
end

#Error

undefined method `post' for #<Spec::DSL::EvalModule:0xb6e7b2e0>


More information about the rspec-users mailing list