diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/commands/test.rb | 6 | ||||
-rw-r--r-- | railties/test/application/test_test.rb | 34 |
3 files changed, 40 insertions, 4 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 219c2fa4e0..03884a073a 100644 --- a/railties/lib/rails/commands/test.rb +++ b/railties/lib/rails/commands/test.rb @@ -1,9 +1,9 @@ require "rails/test_unit/minitest_plugin" if defined?(ENGINE_ROOT) - $: << File.expand_path("test", ENGINE_ROOT) + $LOAD_PATH << File.expand_path("test", ENGINE_ROOT) else - $: << File.expand_path("../../test", APP_PATH) + $LOAD_PATH << File.expand_path("../../test", APP_PATH) end -exit Minitest.run(ARGV) +require "minitest/autorun" diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index 838adbbda9..32d2a6857c 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -12,7 +12,7 @@ module ApplicationTests teardown_app end - test "truth" do + test "simple successful test" do app_file "test/unit/foo_test.rb", <<-RUBY require 'test_helper' @@ -26,6 +26,38 @@ 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' + + class FooTest < ActiveSupport::TestCase + def test_truth + assert false + end + end + RUBY + + assert_unsuccessful_run "unit/foo_test.rb", "Failed assertion" + end + test "integration test" do controller "posts", <<-RUBY class PostsController < ActionController::Base |