before(:each) vs just before

一个人想着一个人 提交于 2020-07-18 08:51:32

问题


I am new to ruby on rails. And playing around with testing

Is there a difference between

before(:each) do 
  #some test code
end

and

before do
  #some test code
end

回答1:


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.

Here is a helpful tidbit from the RSpec RDoc, Module: RSpec::Core::Hooks#before:

Parameters:

  • 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.


来源:https://stackoverflow.com/questions/17584161/beforeeach-vs-just-before

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!