[rspec-devel] Should all teardown blocks run regardless of error?

aslak hellesoy aslak.hellesoy at gmail.com
Wed Jun 27 11:10:09 EDT 2007


I was just bitten by some unexpected behaviour. Look at the following spec.

Spec::Runner.configure do |config|
  config.after(:each) do
    puts "C"
  end
end

describe "examples and teardowns" do
  it "should all run" do
    puts "A"
  end

  after(:each) do
    puts "B"
    raise "oh no"
  end
end

I would have expected to see:

A
B
C

But in fact I see:

A
B

The last (global) teardown doesn't get run - the first teardown block
raising an error causes the other ones to not be run at all. This
seems inconsistent to me - if an example fails, the (first) teardown
will still run.

I'd like to change this so that all teardowns get run, even if
previous ones fail (likewise for multiple setups). Does anyone have
any objections to that?

Aslak


More information about the rspec-devel mailing list