In RSpec, what's the difference between before(:suite) and before(:all)?
rspec, rspec2
Solution
When a `before(:all)` is defined in the `RSpec.configure` block it is called before each top level example group, while a `before(:suite)` code block is only called once.
Here's an example:
RSpec.configure do |config|
config.before(:all) { puts 'Before :all' }
config.after(:all) { puts 'After :all' }
config.before(:suite) { puts 'Before :suite' }
config.after(:suite) { puts 'After :suite' }
end
describe 'spec1' do
example 'spec1' do
puts 'spec1'
end
end
describe 'spec2' do
example 'spec2' do
puts 'spec2'
end
end
Output:
Before :suite
Before :all
spec1
After :all
Before :all
spec2
After :all
After :suite
Problem
The before and after hook documentation on Relish only shows that `before(:suite)` is called prior to `before(:all)`. When should I use one over the other?