【发布时间】:2020-08-12 03:22:48
【问题描述】:
def some_method
subject.put(1)
subject.put(2)
...
end
以下失败,因为对put 的调用不止一次,是否可以仅验证第一次调用发生而不关心其余的调用?
expect(subject).to receive(:put).with(1).once
【问题讨论】:
标签: ruby-on-rails ruby rspec
def some_method
subject.put(1)
subject.put(2)
...
end
以下失败,因为对put 的调用不止一次,是否可以仅验证第一次调用发生而不关心其余的调用?
expect(subject).to receive(:put).with(1).once
【问题讨论】:
标签: ruby-on-rails ruby rspec
玩了一会儿,下面的工作。
allow(subject).to receive(:put)
expect(subject).to receive(:put).with(1).once
【讨论】:
通常你会像这样分开设置和期望:
before do
allow(subject).to receive(:put)
end
it 'invokes put' do
expect(subject).to receive(:put).with(1).once
end
【讨论】: