我可以在 should_receive 上设置期望值并让它执行原始代码吗? [英] Can I set an expectancy on should_receive and have it execute the original code?

查看:37
本文介绍了我可以在 should_receive 上设置期望值并让它执行原始代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的东西:

value = nil

if some_condition
  value =my_object.do_stuff()
end

在我的测试中,我有以下内容:

And in my test, I have the follwing:

MyObject.any_instance.should_receive(:do_stuff)

但是,我只想测试该方法是否被调用,并让它执行原始代码.我不想这样做:

However, I'd like to just test that the method was called, and have it execute the original code. I'd like to NOT have to do it like:

MyObject.any_instance.should_receive(:do_stuff).and_return(:some_dummy_value)

有没有办法做到这一点?

Is there a way of doing that?

推荐答案

and_call_original方法:

MyObject.any_instance.should_receive(:do_stuff).and_call_original

参见 https://github.com/rspec/rspec-mocks#delegating-to-the-original-implementation

这篇关于我可以在 should_receive 上设置期望值并让它执行原始代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆