rspec 3 - 存根类方法 [英] rspec 3 - stub a class method
本文介绍了rspec 3 - 存根类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从 rspec 2.99 升级到 rspec 3.0.3,并已将实例方法转换为使用 allow_any_instance_of
,但还没有弄清楚如何存根类方法.我有这样的代码:
I am upgrading from rspec 2.99 to rspec 3.0.3 and have converted instance methods to use allow_any_instance_of
, but haven't figured out how to stub a class method. I have code like this:
module MyMod
class Utils
def self.find_x(myarg)
# Stuff
end
end
end
我的 rspec 2 测试就是这样做的:
and my rspec 2 test does this:
MyMod::Utils.stub(:find_x).and_return({something: 'testing'})
Rspec 3 的做法是什么?
What is the Rspec 3 way of doing this?
推荐答案
你应该做的
allow(MyMod::Utils).to receive(:find_x).and_return({something: 'testing'})
查看文档方法存根.
这篇关于rspec 3 - 存根类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文