之前(:每个)与之前 [英] before(:each) vs just before
本文介绍了之前(:每个)与之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 ruby on rails 的新手.并进行测试
I am new to ruby on rails. And playing around with testing
有区别吗
before(:each) do
#some test code
end
和
before do
#some test code
end
推荐答案
before
方法接受一个 scope
参数,默认为 :each
.当你省略它时,它暗示你的意思是 :each
,所以你的两个例子做的完全一样.
The before
method accepts a scope
parameter that defaults to :each
. When you leave it out, it's implied that you mean :each
, so your two examples do the exact same thing.
这是来自 RSpec RDoc 的有用花絮,模块:RSpec::Core::Hooks#before:
Here is a helpful tidbit from the RSpec RDoc, Module: RSpec::Core::Hooks#before:
参数:
- 范围(符号)——
:each
、:all
或:suite
(默认为:each
) - conditions (Hash) — 将此钩子限制为匹配这些条件的示例,例如
before(:each, :ui => true) { ... }
将只与使用:ui => 声明的示例或组一起运行.真的
.
- scope (Symbol) —
:each
,:all
, or:suite
(defaults to:each
) - conditions (Hash) — constrains this hook to examples matching these conditions e.g.
before(:each, :ui => true) { ... }
will only run with examples or groups declared with:ui => true
.
这篇关于之前(:每个)与之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文