在给定的 RSpec describe 块中,let、before 和 it 语句的顺序重要吗? [英] Within a given RSpec describe block, does the order of let, before and it statements matter?
问题描述
如果我在 RSpec 中有一个 describe
语句和一组 let
、before
和 it
语句,只要保持给定类型的语句内的顺序,这些语句的特定交错是否会影响行为?例如,将:
If I have a describe
statement in RSpec with a set of let
, before
and it
statements, does the specific interleaving of those statements affect the behavior as long as the order within a given type of statement is maintained? For example, will:
describe "ordering test" do
<it1>
<it2>
<before1>
<let1>
<let2>
<before2>
end
总是产生与以下相同的结果:
always produce the same result as:
describe "ordering test" do
<let1>
<let2>
<before1>
<before2>
<it1>
<it2>
end
其中
和
是对应xxx
语句的实例?
where <xxx1>
and <xxx2>
are instances of the corresponding xxx
statements?
推荐答案
不,顺序无关紧要,对 describe
块中的顶级语句的非 Proc 参数的任何依赖项取模.
No, the ordering does not matter, modulo any dependencies of the non-Proc arguments on top-level statements in the describe
block.
基本上,describe
收集传递给它的 let
、before
和 it
的所有参数的值语句,然后执行所有 let
,然后是所有 before
,然后是所有 it
.
Basically, the describe
collects the values of all the arguments passed into its let
, before
and it
statements, then executes all the let
s, followed by all the before
s, followed by all the it
s.
考虑到正常的 RSpec 用法,第一句中提到的例外情况很少发生.
The exception noted in the first sentence would be a rare occurrence, given normal RSpec usage.
这篇关于在给定的 RSpec describe 块中,let、before 和 it 语句的顺序重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!