[rspec-users] Specifying that code is called in a block

Ashley Moran work at ashleymoran.me.uk
Wed Feb 28 12:26:46 EST 2007


Not sure if this is possible currently.

I have a section of code like this:

   ActiveRecord::Base.transaction do
     cow.save!
     duck.save!
     dog.save!
   end

(Names changed to protect the innocent.)

I'd like to specify that the saves run in a transaction.  I can do

   ActiveRecord::Base.should_receive(:transaction).and_yield

But is there any way to specify that the code is called as above, and  
not as

   cow.save!
   ActiveRecord::Base.transaction do
     duck.save!
   end
   dog.save!

?

Ta
Ashley


More information about the rspec-users mailing list