有没有一种方法可以只为特定的参数创建存根方法.像这样的
boss.stub(:fire!).with(employee1).and_return(true)
如果任何其他员工被传递到boss.fire!
方法,我将得到boss received unexpected message
个错误,但我真正想要的是覆盖特定参数的方法,并将其留给所有其他人.
你知道怎么做吗?
有没有一种方法可以只为特定的参数创建存根方法.像这样的
boss.stub(:fire!).with(employee1).and_return(true)
如果任何其他员工被传递到boss.fire!
方法,我将得到boss received unexpected message
个错误,但我真正想要的是覆盖特定参数的方法,并将其留给所有其他人.
你知道怎么做吗?
您可以为fire!
方法添加一个默认存根,该方法将调用原始实现:
boss.stub(:fire!).and_call_original
boss.stub(:fire!).with(employee1).and_return(true)
Rspec 3语法(@pk nb)
allow(boss).to receive(:fire!).and_call_original
allow(boss).to receive(:fire!).with(employee1).and_return(true)