RSpec before/after 钩子之间的混淆
Confusion between the RSpec before/after hooks
我已经使用 RSpec 3 几天了,我意识到我并不完全理解所提供的 before/after 钩子。
我的困惑在两个方面 -
- 可用的各种挂钩参数 -
:suite
、:context
、:example
、:all
、:each
(我是否遗漏了任何参数?)。前三个似乎是新的,因为我只见过最后两个。最后两个现在是否已弃用并被其他人取代?
- 以上各项涵盖的范围-
- 我猜
before(:context)
和 before(:example)
运行 在每个 context
块和单个示例之前一次。
-
before(:suite)
运行 是否在给定 _spec
文件中的所有示例之前?
- 每个
before(:xxx)
块是否仅适用于其自身嵌套级别及以下的上下文和示例?
谢谢!
根据 documentation,:context
和 :example
在 rspec3 中别名为 :all
和 :each
。
Note: the :example and :context scopes are also available as :each and
:all, respectively. Use whichever you prefer.
首先执行 before :suite
作用域,然后执行 :context
和 :example
作用域:
before :suite
before :context
before :example
after :example
after :context
after :suite
除此之外,我建议您阅读文档,其中包括特定测试场景的工作示例。
我已经使用 RSpec 3 几天了,我意识到我并不完全理解所提供的 before/after 钩子。
我的困惑在两个方面 -
- 可用的各种挂钩参数 -
:suite
、:context
、:example
、:all
、:each
(我是否遗漏了任何参数?)。前三个似乎是新的,因为我只见过最后两个。最后两个现在是否已弃用并被其他人取代? - 以上各项涵盖的范围-
- 我猜
before(:context)
和before(:example)
运行 在每个context
块和单个示例之前一次。 -
before(:suite)
运行 是否在给定_spec
文件中的所有示例之前? - 每个
before(:xxx)
块是否仅适用于其自身嵌套级别及以下的上下文和示例?
- 我猜
谢谢!
根据 documentation,:context
和 :example
在 rspec3 中别名为 :all
和 :each
。
Note: the :example and :context scopes are also available as :each and :all, respectively. Use whichever you prefer.
首先执行 before :suite
作用域,然后执行 :context
和 :example
作用域:
before :suite
before :context
before :example
after :example
after :context
after :suite
除此之外,我建议您阅读文档,其中包括特定测试场景的工作示例。