[rspec-users] stub followed by should_receive behavior changed

Lenny Marks lenny at aps.org
Thu Oct 30 16:35:35 EDT 2008

I'm in the process of trying to get updated to rspec-1.1.11(from  
1.1.1). I have a couple of places where I was trying to verify that a  
particular collaboration was made inside a transaction. My general  
strategy was to start off using something like Transaction.stub! 
(:execute).and_yield in a before block. Then in the specs to verify  
execution within a transaction I would override the stub with  
Transaction.should_receive(:execute), no and_yield, and check the  
collaborations did not occur. Unfortunately this doesn't work anymore  
and I'm not sure if that was intentional or not.  The following  
example passes in 1.1.1 but not in 1.1.11. Also open to better  


class Klass
    def transaction
       raise "error from implementation"

describe "when using a stub with and_yield" do

    before do
       @klass = Klass.new

    it "should yield without explicit expectation" do
       Proc.new do
          @klass.transaction { raise "error from yield" }
       end.should raise_error("error from yield")

    it "should not yield with explicit expectation without and_yield" do


       @klass.transaction { raise "error from yield" }


More information about the rspec-users mailing list