From b057fab6383e5dd9f376036ce10fa908c0e185cb Mon Sep 17 00:00:00 2001 From: James Mead Date: Mon, 28 May 2012 22:44:28 +0100 Subject: Exceptions like Interrupt should not be rescued. Neither Test::Unit nor MiniTest rescue exceptions like Interrupt or NoMemoryError, but ActiveSupport::Testing::SetupAndTeardown#run which overrides MiniTest::Unit::TestCase#run rescues them. Rescuing an Interrupt exception is annoying, because it means when you are running a lot of tests e.g. when running one of the rake test tasks, you cannot break out using ctrl-C. Rescuing exceptions like NoMemoryError is foolish, because the most sensible thing to happen is for the process to terminate as soon as possible. This solution probably needs some finessing e.g. I'm not clear whether the assumption is that only MiniTest is supported. Also early versions of MiniTest did not have this behaviour. However, hopefully it's a start. Integrating with Test::Unit & MiniTest has always been a pain. It would be great if both of them provided sensible extension points for the kind of things that both Rails and Mocha want to do. --- activesupport/lib/active_support/testing/setup_and_teardown.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 772c7b4209..c6ae6bafa5 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -28,11 +28,15 @@ module ActiveSupport run_callbacks :setup do result = super end + rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS + raise rescue Exception => e result = runner.puke(self.class, method_name, e) ensure begin run_callbacks :teardown + rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS + raise rescue Exception => e result = runner.puke(self.class, method_name, e) end -- cgit v1.2.3 From 7d8e5fac758bebc7199b514b08d4755a6f897435 Mon Sep 17 00:00:00 2001 From: James Mead Date: Tue, 29 May 2012 09:28:22 +0100 Subject: Avoid dependency on MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS. --- .../lib/active_support/testing/setup_and_teardown.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index c6ae6bafa5..527fa555b7 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -4,6 +4,14 @@ require 'active_support/callbacks' module ActiveSupport module Testing module SetupAndTeardown + + PASSTHROUGH_EXCEPTIONS = [ + NoMemoryError, + SignalException, + Interrupt, + SystemExit + ] + extend ActiveSupport::Concern included do @@ -28,14 +36,14 @@ module ActiveSupport run_callbacks :setup do result = super end - rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS + rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e result = runner.puke(self.class, method_name, e) ensure begin run_callbacks :teardown - rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS + rescue *PASSTHROUGH_EXCEPTIONS raise rescue Exception => e result = runner.puke(self.class, method_name, e) -- cgit v1.2.3