在我的一项测试中,我想执行before :all
操作,并且还需要测试在此before :all
操作中未调用方法。有没有办法做到这一点?
e.g。我希望能够:
before :all do
@bar_called = false
# set @bar_called to true if bar is called on an instance of class Foo
do_other_stuff
end
然后,在我之后的一个规范中,期望@bar_called == false
答案 0 :(得分:0)
您还可以使用块实现模拟,然后设置@bar_called
。
expect(obj).to receive(:my_method) { @bar_called = true }
现在,您可能需要考虑在模拟/存根上设置期望
expect(obj).to receive(:my_method).exactly(0).times