rspec 3 - 存根类方法

时间:2014-07-31 18:48:13

标签: ruby-on-rails ruby rspec rspec3

我正在从rspec 2.99升级到rspec 3.0.3,并已将实例方法转换为使用allow_any_instance_of,但尚未弄清楚如何存根类方法。我有这样的代码:

module MyMod
  class Utils
    def self.find_x(myarg)
      # Stuff
    end
  end
end

我的rspec 2测试做到了这一点:

MyMod::Utils.stub(:find_x).and_return({something: 'testing'})

Rspec 3的做法是什么?

1 个答案:

答案 0 :(得分:152)

你应该做

allow(MyMod::Utils).to receive(:find_x).and_return({something: 'testing'})

查看doco Method stubs

相关问题