如何在RSpec中定义当前范围的主题(改进主题)时访问父范围的主题?访问RSpec中的父范围主题?
示例代码:
describe MyModule.method(:some_method) do
context "when called with a String" do
let(:string) { "Hey there!" }
# I want to refine the subject using the parent scope's subject - common case
# is applying a subject method. Something like:
subject { super.subject.call string }
# Use subject...
end # when called with a String
end # MyModule.some_method
就快成功了:'{主题超()}'即可。 – mudasobwa
@mudasobwa真的吗?我会回去再试一次,但是我发誓我在那里有'super.call'(应该和super()。call')一样,并且它不工作... – nrser
@mudasobwa呵呵, super()。call' works('super.call' does not)... weird ...我想我不完全理解'super',我认为这是一个方法调用?无论如何,非常感谢! – nrser