我有使用RSpec沒有太多經驗,我不會傳播關於一個真實的任務,但如果是我遇到的問題將大大簡化,它看起來像這樣:RSpec的:如何剿變量的緩存
describe "Test" do
context "ctx_1" do
before(:all) do
# Changes of $x from "nil" to a some NOT an earlier predefined instance.
# A real case supposes getting this variable from other execution part.
# It is very essential.
$x = [1, 2, 3]
end
$x.each do |e|
context "ctx_2"
before (:all) do
puts "do a some things for #{e}"
end
it "example #{$x.index(e)}" do
puts "do some checking for #{e}"
end
end
end
end
end
有沒有辦法將「ctx 2」換成新的$ x值而沒有兌現值(零)的循環? 問題是$ x的更新值僅在「it」塊內有效。與其他entytyes任何變化(@而不是$,描述,上下文等之前)未通過..
不太清楚你正在嘗試做的,但你不應該使用全局變量設置爲
$x
配置的一部分。 – Stefanheve你用'let'試過了嗎? – pawel7318
是的,我已經讓,讓!而不是之前,但也有同樣的結果。 – Eugene