B.rb看起来像:
module A
module B
def enabled? xxx
xxx == 'a'
end
def disabled? xxx
xxx != 'a'
end
end
end
Run Code Online (Sandbox Code Playgroud)
另一个C.rb如:
module YYY
class C
include A::B
def a_method
if(enabled? xxx)
return 'a'
return 'b'
end
end
Run Code Online (Sandbox Code Playgroud)
现在我想编写单元测试来测试a_method函数,
describe :a_method do
it 'returns a' do
###how to sub enabled? method to make it return true....
end
end
Run Code Online (Sandbox Code Playgroud)
启用?是模型中的实例方法,我试过了
A::B.stub.any_instance(:enabled).and_return true
Run Code Online (Sandbox Code Playgroud)
它不起作用。
有人可以帮助我吗?