Rspec messes up stubs and expectations

less than 1 minute read

Here is an example showing the issue :

before :each do
  @car = stub("a car")
  @car.stub(:move)
end
it "should be possible to mix stubbing and expectations" do
  @car.should_receive(:move).once

  2.times { @car.move }
end

This example should obviously fail, but it passes ! Here is a working (failing) version :

before :each do
  @car = stub("a car")
 end
it "should be possible to mix stubbing and expectations" do
  @car.should_receive(:move).once

  2.times { @car.move }
end

I am using rspec 1.3.0. Did you fall into the same issues ? Is this fixed in rspec 2 ?

I usually write about 15 minutes worth of reading per month. I won't transfer your email. No Spam, unsubscribe whenever you want.

As a gift for subscribing, you'll receive an illustrated mini-ebook "How to start a team coding dojo"!

Categories: ,

Updated:

Leave a comment