aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/commands/test.rb4
-rw-r--r--railties/test/application/test_test.rb18
3 files changed, 25 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 594d239290..b03c87e9ba 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Run `Minitest.after_run` hooks when running `rails test`.
+
+ *Michael Grosser*
+
* Run `before_configuration` callbacks as soon as application constant
inherits from `Rails::Application`.
diff --git a/railties/lib/rails/commands/test.rb b/railties/lib/rails/commands/test.rb
index cc0cc3d65a..f4699b0347 100644
--- a/railties/lib/rails/commands/test.rb
+++ b/railties/lib/rails/commands/test.rb
@@ -6,4 +6,6 @@ else
$LOAD_PATH << File.expand_path("../../test", APP_PATH)
end
-exit Minitest.run(ARGV)
+result = Minitest.run(ARGV)
+Minitest.class_variable_get(:@@after_run).reverse_each(&:call)
+exit result
diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb
index 99d698114c..702a2be5eb 100644
--- a/railties/test/application/test_test.rb
+++ b/railties/test/application/test_test.rb
@@ -26,6 +26,24 @@ module ApplicationTests
assert_successful_test_run "unit/foo_test.rb"
end
+ test "after_run" do
+ app_file "test/unit/foo_test.rb", <<-RUBY
+ require 'test_helper'
+
+ Minitest.after_run { puts "WORLD" }
+ Minitest.after_run { puts "HELLO" }
+
+ class FooTest < ActiveSupport::TestCase
+ def test_truth
+ assert true
+ end
+ end
+ RUBY
+
+ result = assert_successful_test_run "unit/foo_test.rb"
+ assert_equal ["HELLO", "WORLD"], result.scan(/HELLO|WORLD/) # only once and in correct order
+ end
+
test "simple failed test" do
app_file "test/unit/foo_test.rb", <<-RUBY
require 'test_helper'