如何在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