Reputation: 722
What is the difference between these blocks in RSpec and which situation to use before block
before(:each)
end
before
end
Upvotes: 0
Views: 208
Reputation: 2099
:each is the scope, it can be :each which runs the block before each example, or :all which runs the block before all examples.
You use it to run a block before each or all examples to set up your text fixture. you always have to pass a block to before, thus, your syntax above is slightly incorrect, it should be
before(:each) do
...
end
or before(:each) { ... }
see https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/hooks/before-and-after-hooks
Upvotes: 0
Reputation: 10738
There's no difference. :each
is the default option. Unless you specify :each
/:all
, then :each
is used.
Upvotes: 1