Skip to content
This repository
Browse code

Merge pull request #6532 from freerange/3-1-stable-minitest-passthrou…

…gh-exceptions

Exceptions like Interrupt should not be rescued in tests.
  • Loading branch information...
commit 2f428152fa0bde37cf1cd124217f21efaa561ecf 2 parents a74b6a0 + 4cd3285
Rafael Mendonça França authored May 29, 2012
5  activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -28,17 +28,22 @@ def teardown(*args, &block)
28 28
       end
29 29
 
30 30
       module ForMiniTest
  31
+        PASSTHROUGH_EXCEPTIONS = MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
31 32
         def run(runner)
32 33
           result = '.'
33 34
           begin
34 35
             run_callbacks :setup do
35 36
               result = super
36 37
             end
  38
+          rescue *PASSTHROUGH_EXCEPTIONS => e
  39
+            raise e
37 40
           rescue Exception => e
38 41
             result = runner.puke(self.class, method_name, e)
39 42
           ensure
40 43
             begin
41 44
               run_callbacks :teardown
  45
+            rescue *PASSTHROUGH_EXCEPTIONS => e
  46
+              raise e
42 47
             rescue Exception => e
43 48
               result = runner.puke(self.class, method_name, e)
44 49
             end
44  activesupport/test/test_case_test.rb
@@ -19,7 +19,7 @@ def options
19 19
     end
20 20
 
21 21
     if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
22  
-      def test_callback_with_exception
  22
+      def test_standard_error_raised_within_setup_callback_is_puked
23 23
         tc = Class.new(TestCase) do
24 24
           setup :bad_callback
25 25
           def bad_callback; raise 'oh noes' end
@@ -38,7 +38,7 @@ def test_true; assert true end
38 38
         assert_equal 'oh noes', exception.message
39 39
       end
40 40
 
41  
-      def test_teardown_callback_with_exception
  41
+      def test_standard_error_raised_within_teardown_callback_is_puked
42 42
         tc = Class.new(TestCase) do
43 43
           teardown :bad_callback
44 44
           def bad_callback; raise 'oh noes' end
@@ -56,6 +56,46 @@ def test_true; assert true end
56 56
         assert_equal test_name, name
57 57
         assert_equal 'oh noes', exception.message
58 58
       end
  59
+
  60
+      def test_passthrough_exception_raised_within_test_method_is_not_rescued
  61
+        tc = Class.new(TestCase) do
  62
+          def test_which_raises_interrupt; raise Interrupt; end
  63
+        end
  64
+
  65
+        test_name = 'test_which_raises_interrupt'
  66
+        fr = FakeRunner.new
  67
+
  68
+        test = tc.new test_name
  69
+        assert_raises(Interrupt) { test.run fr }
  70
+      end
  71
+
  72
+      def test_passthrough_exception_raised_within_setup_callback_is_not_rescued
  73
+        tc = Class.new(TestCase) do
  74
+          setup :callback_which_raises_interrupt
  75
+          def callback_which_raises_interrupt; raise Interrupt; end
  76
+          def test_true; assert true end
  77
+        end
  78
+
  79
+        test_name = 'test_true'
  80
+        fr = FakeRunner.new
  81
+
  82
+        test = tc.new test_name
  83
+        assert_raises(Interrupt) { test.run fr }
  84
+      end
  85
+
  86
+      def test_passthrough_exception_raised_within_teardown_callback_is_not_rescued
  87
+        tc = Class.new(TestCase) do
  88
+          teardown :callback_which_raises_interrupt
  89
+          def callback_which_raises_interrupt; raise Interrupt; end
  90
+          def test_true; assert true end
  91
+        end
  92
+
  93
+        test_name = 'test_true'
  94
+        fr = FakeRunner.new
  95
+
  96
+        test = tc.new test_name
  97
+        assert_raises(Interrupt) { test.run fr }
  98
+      end
59 99
     end
60 100
   end
61 101
 end

0 notes on commit 2f42815

Please sign in to comment.
Something went wrong with that request. Please try again.