aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-04-06 13:10:08 -0400
committerGitHub <noreply@github.com>2018-04-06 13:10:08 -0400
commit00f2dbd09b676f0efb38f4d1dc2d9f047d838309 (patch)
tree98487d42cc5e0e312652498a44bcff17c5d2c191
parentbe811c33956407e675f94df2859fc2ef0cce8ddb (diff)
parent01eddb390c4016f7af61979519911ed442aa7a06 (diff)
downloadrails-00f2dbd09b676f0efb38f4d1dc2d9f047d838309.tar.gz
rails-00f2dbd09b676f0efb38f4d1dc2d9f047d838309.tar.bz2
rails-00f2dbd09b676f0efb38f4d1dc2d9f047d838309.zip
Merge pull request #32472 from Edouard-chin/ec-activesupport-teardown
`SetupAndTeardown#teardown` should call any subsequent after_teardown:
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb9
-rw-r--r--activesupport/test/testing/after_teardown_test.rb34
2 files changed, 42 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb
index 1dbf3c5da0..35236f1401 100644
--- a/activesupport/lib/active_support/testing/setup_and_teardown.rb
+++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -44,8 +44,15 @@ module ActiveSupport
end
def after_teardown # :nodoc:
- run_callbacks :teardown
+ begin
+ run_callbacks :teardown
+ rescue => e
+ error = e
+ end
+
super
+ ensure
+ raise error if error
end
end
end
diff --git a/activesupport/test/testing/after_teardown_test.rb b/activesupport/test/testing/after_teardown_test.rb
new file mode 100644
index 0000000000..68c368909c
--- /dev/null
+++ b/activesupport/test/testing/after_teardown_test.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require "abstract_unit"
+
+module OtherAfterTeardown
+ def after_teardown
+ @witness = true
+ end
+end
+
+class AfterTeardownTest < Minitest::Test
+ include OtherAfterTeardown
+ include ActiveSupport::Testing::SetupAndTeardown
+
+ attr_writer :witness
+
+ MyError = Class.new(StandardError)
+
+ teardown do
+ raise MyError, "Test raises an error, all after_teardown should still get called"
+ end
+
+ def after_teardown
+ assert_raises MyError do
+ super
+ end
+
+ assert_equal true, @witness
+ end
+
+ def test_teardown_raise_but_all_after_teardown_method_are_called
+ assert true
+ end
+end