In RSpec, what's the difference between before(:suite) and before(:all)?
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