aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Grosser <michael@grosser.it>2016-09-16 09:31:39 -0700
committerMichael Grosser <michael@grosser.it>2016-09-16 09:36:29 -0700
commit45dce0c0030129b86413fbcbaa4f71f721847509 (patch)
tree53ce721846cfaa4a4507c7c7ea8caa6144b63168
parentfe98d21289b7510182e338f352f5a416bd01f1ad (diff)
downloadrails-45dce0c0030129b86413fbcbaa4f71f721847509.tar.gz
rails-45dce0c0030129b86413fbcbaa4f71f721847509.tar.bz2
rails-45dce0c0030129b86413fbcbaa4f71f721847509.zip
support minitest after_run for parity to regular minitest
see https://github.com/seattlerb/minitest/blob/f9605387e4af7d657921a83aaf0ae364f6d26a57/lib/minitest.rb#L51-L65
-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'