rspec mock 多次
rspec mock 同一个方法多次
def mock_1
Car.should.receive(:new)
end
def mock_2
Car.should.receive(:new)
end
mock_1
mock_2
class Peo
car = Car.new
end
实际代码里只调用一次Car.new,但mock的时候用了2次,运行时提示expected :new with (any args) once, but received it 0 times
解决方法,mock一次Car.new即可。
以上程序运行环境rspec 1.3.2