我需要检查是否调用了特定方法。btakita/rr 有可能吗?
rspec 示例来自: https ://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/calling-the-original-method !
Addition.should_receive(:two_plus_two).and_call_original
我需要检查是否调用了特定方法。btakita/rr 有可能吗?
rspec 示例来自: https ://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/calling-the-original-method !
Addition.should_receive(:two_plus_two).and_call_original
根据原始 rr 公告,您需要使用以下方法:
original_two_plus_two = Addition.method(:two_plus_two)
mock(Addition).two_plus_two {original_two_plus_two.call}
但是,如果您对在原始代码之后调用 double 没问题,那么您可以使用 rr 的代理功能,在https://github.com/rr/rr#proxies中进行了描述,如下所示:
mock.proxy(Addition).two_plus_two
(感谢@ElliotWinkler 澄清在这种情况下不需要阻止。)