以下代码不起作用,但它最好地显示了我想要实现的目标
context "this context describes the class" do
subject do
# described class is actually a module here
c = Class.new.extend(described_class)
c.some_method_that_has_been_added_through_extension
c
end
# ... testing the class itself here ...
context "instances of this class" do
subject do
# this doesn't work because it introduces a endless recursion bug
# which makes perfectly sense
subject.new
end
end
end
我还尝试在使用主题初始化的内部上下文中使用局部变量,但没有运气。有什么方法可以从内部范围的主题定义中访问外部范围的主题?