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

Dan North dan at tastapod.com
Wed Jun 27 14:39:43 EDT 2007


I agree completely. Whenever I implement or override tearDown in a junit 
testcase, I use this template:

try {
    // my teardown stuff
}
finally {
    super.tearDown();
}



aslak hellesoy wrote:
> Old words die hard. I meant *after* blocks, not teardown ;-)
>
> On 6/27/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
>   
>> 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
>>
>>     
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20070627/0af326a6/attachment.html 


More information about the rspec-devel mailing list