【发布时间】:2012-06-13 14:26:42
【问题描述】:
我有下一个模块。
module A
module B
def self.method_b(value)
#code
end
end
end
和
module A
module C
def self.method_c(value)
A::B.method_b(value)
end
end
end
如何测试这些模块?如何创建存根 self.method_b?
spec_helper.rb
RSpec.configure do |config|
config.mock_with :mocha
end
谢谢。
【问题讨论】:
-
A::B.stub(:method_b).and_return("whatever") -
NoMethodError:undefined method 'stub' for A::B:Module -
对我来说似乎是 RSpec 中的一个错误。
#stub应该适用于所有对象:-\ -
看看我的
spec_helper.rb。可能需要在 spec_helper 中添加一些东西?