Skip to content

All after hooks should be run even if the first one fails

Created by: JonRowe

We have a bunch of initialisation run before and after every spec which absloutely must be cleaned up. So naturally we put the cleanup in after(:all).

Now, supposing you have a spec with an after block which is misbehaving:

describe "before and after callbacks" do
  # in reality these are done in the rspec config
  before(:all) do
    puts "before all"
  end
  after(:all) do
    puts "after all"
  end

  # in reality this is done in the specific spec
  after(:all) do
    puts "after all 2"
    raise "oops, something broke"
  end

  it "does something" do
  end
end

In this situation, rspec (2.14.4) hits the error in the the second after(:all) and then skips running the other one. Every subsequent spec then fails when their initialisation tries to initialise after not properly shutting down.

I think that the correct behaviour would be to attempt to run all after blocks even if the first one fails.

Merge request reports