我正在测试我的模块,我决定测试它与匿名类:
subject(:klass) { Class.new { include MyModule } }
MyModule在klass中使用方法名称.为了让我的规范工作,我需要存根这个方法名称(未实现).所以我写道:
subject { klass.new } allow(subject).to receive(:name).and_return('SOreadytohelp') }
但它引起了:
RSpec::Mocks::MockExpectationError: #<#<Class:0x007feb67a17750>:0x007feb67c7adf8> does not implement: name from spec-support-3.3.0/lib/rspec/support.rb:86:in `block in <module:Support>'
如何在不定义的情况下存根此方法?