【发布时间】:2014-01-03 08:06:11
【问题描述】:
我有一个类似的规格
describe MyClass do
it_behaves_like SharedClass, MyClass.new
end
在我共享的示例规范中,我有
shared_examples_for SharedClass do |instance|
before do
instance.some_my_class_method = double
end
# some specs here
end
MyClass 实例中的一些方法我无法在 shared_examples_for 块中存根,因此我想在将它们传递给 it_behaves_like 语句之前先存根它们。喜欢,
describe MyClass do
before do
@instance = MyClass.new
@instance.stub(:my_class_method)
end
it_behaves_like SharedClass, @instance
end
但我不能那样做。它把我扔了
无方法错误:
nil:NilClass 的未定义方法 `some_my_class_method='
不知何故,我无法在 shared_examples_for 上下文中访问该 @instance 对象。 我正在使用 ruby 1.9.3p392 和 rspec (2.14.1)
【问题讨论】:
标签: rspec