本文介绍了rspec2 中类的“存根"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
describe SomeThing do
before :all do
# ...
FooClass.stub(:fooMethod).with('a').and_return("something")
end
end
使用 rspec 1
很酷.
我已经更新到 rspec 2
,这就是我现在收到的这条线:
I've updated to rspec 2
, and this is what i'm receiving for this line now:
Failure/Error:
FooClass.stub(:fooMethod).with('a').and_return("something")
NoMethodError:
undefined method `stub' for FooClass::Class
rspec api 但说:Person.stub(:find){ person }
我错过了什么?
推荐答案
这是在 it
还是 before
块中?
Is this inside an it
or before
block?
在 before :all
块中不支持存根.在每个示例之后,存根和模拟都会被清除.您可以在此处阅读有关此内容的更多信息.将 before :all do
更改为 before do
,这应该可以工作.
Stubs are not supported in before :all
blocks. Stubs and mocks get cleared after each example. You can read more about this here. Change the before :all do
to before do
and this should work.
这篇关于rspec2 中类的“存根"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!