新手问题 Rspec 如何 mock class 方法

chucai · 2012年07月27日 · 最后由 chucai 回复于 2012年07月28日 · 2582 次阅读

我有一个类

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 谢谢。这个不是只返回 实例方法么?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号