RSpec:存根内核::睡眠? [英] RSpec: stubbing Kernel::sleep?
本文介绍了RSpec:存根内核::睡眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 rspec 场景中存根 Kernel.sleep?
Is there a way to stub Kernel.sleep in an rspec scenario?
推荐答案
如果你在一个对象的上下文中调用 sleep,你应该在对象上存根它,像这样:
If you are calling sleep within the context of an object, you should stub it on the object, like so:
class Foo
def self.some_method
sleep 5
end
end
it "should call sleep" do
Foo.stub!(:sleep)
Foo.should_receive(:sleep).with(5)
Foo.some_method
end
关键是,在调用 sleep 的上下文中对任何self"进行存根.
The key is, to stub sleep on whatever "self" is in the context where sleep is called.
这篇关于RSpec:存根内核::睡眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文