Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

before(:each) vs just before

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
like image 691
dboyd68 Avatar asked Jul 11 '13 02:07

dboyd68


1 Answers

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.
like image 106
Chris Peters Avatar answered Sep 30 '22 19:09

Chris Peters