是否有可能做这样的事情?RSpec之前在帮手
module MyHelper
before (:each) do
allow(Class).to receive(:method).and_return(true)
end
end
然后在我的测试中,我可以这样做:
RSpec.describe 'My cool test' do
include MyHelper
it 'Tests a Class Method' do
expect { Class.method }.to eq true
end
end
编辑:这将产生以下错误:
undefined method `before' for MyHelper:Module (NoMethodError)
基本上我有一个情况许多测试做了不同的事情,但一个共同的模型跨越了他们之后的反应_commit最终总是调用一个与API对话的方法。我不希望全球允许Class
收到:method
,有时候,我需要自己定义它以适应特殊情况......但我不想重复我的allow/receive/and_return,而是将它包装在一个共同的帮助器中...
完美的解决方案!:) –
这指甲!谢谢@Stefan :) – Nick