Posted almost 4 years ago. Visible to the public. Repeats.

Rspec: around(:all) and around(:each) hook execution order


  • around(:suite) does not exist.
  • around(:all) runs after before(:all) and before after(:all).
  • around(:each) runs before before(:each) and after after(:each).

As this is not 100% obvious (and not yet documented) it is written down in this card. In RSpec 3 :each has the alias :example and :all the alias :context.


RSpec.configure do |config| config.before(:suite) { puts 'BEFORE :suite' } config.after(:suite) { puts 'AFTER :suite' } end describe 'order of hook execution' do around(:all) do |each| puts 'AROUND BEFORE :all' puts 'AROUND AFTER :all' end around(:each) do |each| puts 'AROUND BEFORE :each' puts 'AROUND AFTER :each' end before(:all) { puts 'BEFORE :all' } before(:each) { puts 'BEFORE :each' } after(:each) { puts 'AFTER :each' } after(:all) { puts 'AFTER :all' } it { expect(true).to be(true) } end
BEFORE :suite BEFORE :all AROUND BEFORE :all AROUND BEFORE :each BEFORE :each . # our each runs here AFTER :each AROUND AFTER :each AROUND AFTER :all AFTER :all AFTER :suite

Further around hook related problems

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Emanuel De
Last edit:
over 1 year ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more