aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/testing
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2018-04-05 22:22:46 -0400
committerEdouard CHIN <edouard.chin@shopify.com>2018-04-06 04:54:56 -0400
commit70fae9a434d64238663fea3d4c6abdc86206a0f2 (patch)
tree131f45061347d6a880fdbfd3759b7854fba2a00c /activesupport/test/testing
parentd514ce9199fac58e569482dc901e53d0526abdf7 (diff)
downloadrails-70fae9a434d64238663fea3d4c6abdc86206a0f2.tar.gz
rails-70fae9a434d64238663fea3d4c6abdc86206a0f2.tar.bz2
rails-70fae9a434d64238663fea3d4c6abdc86206a0f2.zip
`SetupAndTeardown#teardown` should call any subsequent after_teardown:
If you have a regular test that have a teardown block, and for any reason an exception get raised, ActiveSupport will not run subsequent after_teardown method provided by other module or gems. One of them being the ActiveRecord::TestFixtures which won't rollback the transation when the test ends making all subsequent test to be in a weird state. The default implementation of minitest is to run all teardown methods from the user's test, rescue all exceptions, run all after_teardown methods provided by libraries and finally re-raise the exception that happened in the user's teardown method. Rails should do the same.
Diffstat (limited to 'activesupport/test/testing')
-rw-r--r--activesupport/test/testing/setup_and_teardown_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activesupport/test/testing/setup_and_teardown_test.rb b/activesupport/test/testing/setup_and_teardown_test.rb
new file mode 100644
index 0000000000..283f82d19a
--- /dev/null
+++ b/activesupport/test/testing/setup_and_teardown_test.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require "abstract_unit"
+
+module OtherAfterTeardown
+ def after_teardown
+ @witness = true
+ end
+end
+
+class SetupAndTeardownTest < 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