问题
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