新手问题 Rspec 如何 mock class 方法

chucai · July 27, 2012 · Last by chucai replied at July 28, 2012 · 2582 hits

我有一个类

class Message
  class << self
     def method_a(key)
       [1,2]
     end
  end
end

我现在需要 mock method_a 该怎么写 rsepc 代码?

谢谢

很简单啊:

Message.stub(:method_a).and_return([1,2])

#1 楼 @lyfi2003 谢谢。这个不是只返回 实例方法么?

You need to Sign in before reply, if you don't have an account, please Sign up first.