From 3073c531983de243219fb55be93fbcebfdd9c44e Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Mon, 6 May 2013 17:38:45 -0700 Subject: [PATCH 1/3] Updates to make rails 4 happy with minitest 5: + Namespace changes, overhaul of runners. + Internal ivar name changes - Removed a logger globally applied to tests that spew everywhere?!? + Override Minitest#__run to sort tests by name. + Reworked testing isolation to work with the new cleaner architecture. - Removed a bunch of tests that just test minitest straight up. I think these changes were all merged to minitest 4 a long time ago. - Minor report output differences. --- actionpack/lib/action_view/test_case.rb | 4 +- activemodel/test/cases/railtie_test.rb | 1 - activesupport/lib/active_support/test_case.rb | 24 +++- .../lib/active_support/testing/autorun.rb | 4 +- .../lib/active_support/testing/isolation.rb | 17 +-- .../active_support/testing/tagged_logging.rb | 2 +- activesupport/test/test_case_test.rb | 110 ------------------ activesupport/test/test_test.rb | 2 +- railties/test/application/rake_test.rb | 4 +- railties/test/application/test_runner_test.rb | 20 ++-- .../generators/plugin_new_generator_test.rb | 4 +- 11 files changed, 48 insertions(+), 144 deletions(-) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 10b487f37af..3145446114a 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -211,7 +211,9 @@ module ActionView alias_method :_view, :view INTERNAL_IVARS = [ - :@__name__, + :@NAME, + :@failures, + :@assertions, :@__io__, :@_assertion_wrapped, :@_assertions, diff --git a/activemodel/test/cases/railtie_test.rb b/activemodel/test/cases/railtie_test.rb index a0cd1402b1a..d44a3448df1 100644 --- a/activemodel/test/cases/railtie_test.rb +++ b/activemodel/test/cases/railtie_test.rb @@ -9,7 +9,6 @@ class RailtieTest < ActiveModel::TestCase @app ||= Class.new(::Rails::Application) do config.eager_load = false - config.logger = Logger.new(STDOUT) end end diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 8b392c36d0e..f0962998a02 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -16,10 +16,28 @@ begin rescue LoadError end +module Minitest # :nodoc: + class << self + remove_method :__run + end + + def self.__run reporter, options # :nodoc: + # FIXME: MT5's runnables is not ordered. This is needed because + # we have have tests have cross-class order-dependent bugs. + suites = Runnable.runnables.sort_by { |ts| ts.name.to_s } + + parallel, serial = suites.partition { |s| s.test_order == :parallel } + + ParallelEach.new(parallel).map { |suite| suite.run reporter, options } + + serial.map { |suite| suite.run reporter, options } + end +end + module ActiveSupport - class TestCase < ::MiniTest::Unit::TestCase - Assertion = MiniTest::Assertion - alias_method :method_name, :__name__ + class TestCase < ::Minitest::Test + Assertion = Minitest::Assertion + + alias_method :method_name, :name $tags = {} def self.for_tag(tag) diff --git a/activesupport/lib/active_support/testing/autorun.rb b/activesupport/lib/active_support/testing/autorun.rb index c446adc16dd..45d8193abbc 100644 --- a/activesupport/lib/active_support/testing/autorun.rb +++ b/activesupport/lib/active_support/testing/autorun.rb @@ -1,5 +1,5 @@ gem 'minitest' -require 'minitest/unit' +require 'minitest/autorun' -MiniTest::Unit.autorun +Minitest.autorun diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index e16b73a036c..9c52ae7768c 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -72,16 +72,12 @@ module ActiveSupport end end - def run(runner) - _run_class_setup - - serialized = run_in_isolation do |isolated_runner| - super(isolated_runner) + def run + serialized = run_in_isolation do + super end - retval, proxy = Marshal.load(serialized) - proxy.__replay__(runner) - retval + Marshal.load(serialized) end module Forking @@ -90,9 +86,8 @@ module ActiveSupport pid = fork do read.close - proxy = ProxyTestResult.new - retval = yield proxy - write.puts [Marshal.dump([retval, proxy])].pack("m") + yield + write.puts [Marshal.dump(self.dup)].pack("m") exit! end diff --git a/activesupport/lib/active_support/testing/tagged_logging.rb b/activesupport/lib/active_support/testing/tagged_logging.rb index 9d43eb179f5..f4cee640916 100644 --- a/activesupport/lib/active_support/testing/tagged_logging.rb +++ b/activesupport/lib/active_support/testing/tagged_logging.rb @@ -7,7 +7,7 @@ module ActiveSupport def before_setup if tagged_logger - heading = "#{self.class}: #{__name__}" + heading = "#{self.class}: #{name}" divider = '-' * heading.size tagged_logger.info divider tagged_logger.info heading diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index a1bdcf23960..08df67827e2 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -2,116 +2,6 @@ require 'abstract_unit' module ActiveSupport class TestCaseTest < ActiveSupport::TestCase - class FakeRunner - attr_reader :puked - - def initialize - @puked = [] - end - - def puke(klass, name, e) - @puked << [klass, name, e] - end - - def options - nil - end - - def record(*args) - end - - def info_signal - end - end - - def test_standard_error_raised_within_setup_callback_is_puked - tc = Class.new(TestCase) do - def self.name; nil; end - - setup :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first - - assert_equal tc, klass - assert_equal test_name, name - assert_equal 'oh noes', exception.message - end - - def test_standard_error_raised_within_teardown_callback_is_puked - tc = Class.new(TestCase) do - def self.name; nil; end - - teardown :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first - - assert_equal tc, klass - assert_equal test_name, name - assert_equal 'oh noes', exception.message - end - - def test_passthrough_exception_raised_within_test_method_is_not_rescued - tc = Class.new(TestCase) do - def self.name; nil; end - - def test_which_raises_interrupt; raise Interrupt; end - end - - test_name = 'test_which_raises_interrupt' - fr = FakeRunner.new - - test = tc.new test_name - assert_raises(Interrupt) { test.run fr } - end - - def test_passthrough_exception_raised_within_setup_callback_is_not_rescued - tc = Class.new(TestCase) do - def self.name; nil; end - - setup :callback_which_raises_interrupt - def callback_which_raises_interrupt; raise Interrupt; end - def test_true; assert true end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - assert_raises(Interrupt) { test.run fr } - end - - def test_passthrough_exception_raised_within_teardown_callback_is_not_rescued - tc = Class.new(TestCase) do - def self.name; nil; end - - teardown :callback_which_raises_interrupt - def callback_which_raises_interrupt; raise Interrupt; end - def test_true; assert true end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - assert_raises(Interrupt) { test.run fr } - end - def test_pending_deprecation assert_deprecated do pending "should use #skip instead" diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 3e6ac811a48..68f9ec6c009 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -201,6 +201,6 @@ class TestCaseTaggedLoggingTest < ActiveSupport::TestCase end def test_logs_tagged_with_current_test_case - assert_match "#{self.class}: #{__name__}\n", @out.string + assert_match "#{self.class}: #{name}\n", @out.string end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index fa3ab969ae2..6703f8df510 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -214,7 +214,7 @@ module ApplicationTests bundle exec rake db:migrate db:test:clone test` end - assert_match(/7 tests, 13 assertions, 0 failures, 0 errors/, output) + assert_match(/7 runs, 13 assertions, 0 failures, 0 errors/, output) assert_no_match(/Errors running/, output) end @@ -224,7 +224,7 @@ module ApplicationTests bundle exec rake db:migrate db:test:clone test` end - assert_match(/7 tests, 13 assertions, 0 failures, 0 errors/, output) + assert_match(/7 runs, 13 assertions, 0 failures, 0 errors/, output) assert_no_match(/Errors running/, output) end diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 1cf53aa4fba..118f22995e9 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -32,13 +32,13 @@ module ApplicationTests def test_run_single_file create_test_file :models, 'foo' create_test_file :models, 'bar' - assert_match "1 tests, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb") + assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb") end def test_run_multiple_files create_test_file :models, 'foo' create_test_file :models, 'bar' - assert_match "2 tests, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb") + assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb") end def test_run_file_with_syntax_error @@ -59,7 +59,7 @@ module ApplicationTests run_test_models_command.tap do |output| assert_match "FooTest", output assert_match "BarTest", output - assert_match "2 tests, 2 assertions, 0 failures", output + assert_match "2 runs, 2 assertions, 0 failures", output end end @@ -70,7 +70,7 @@ module ApplicationTests run_test_helpers_command.tap do |output| assert_match "FooHelperTest", output assert_match "BarHelperTest", output - assert_match "2 tests, 2 assertions, 0 failures", output + assert_match "2 runs, 2 assertions, 0 failures", output end end @@ -83,7 +83,7 @@ module ApplicationTests assert_match "FooTest", output assert_match "BarHelperTest", output assert_match "BazUnitTest", output - assert_match "3 tests, 3 assertions, 0 failures", output + assert_match "3 runs, 3 assertions, 0 failures", output end end @@ -94,7 +94,7 @@ module ApplicationTests run_test_controllers_command.tap do |output| assert_match "FooControllerTest", output assert_match "BarControllerTest", output - assert_match "2 tests, 2 assertions, 0 failures", output + assert_match "2 runs, 2 assertions, 0 failures", output end end @@ -105,7 +105,7 @@ module ApplicationTests run_test_mailers_command.tap do |output| assert_match "FooMailerTest", output assert_match "BarMailerTest", output - assert_match "2 tests, 2 assertions, 0 failures", output + assert_match "2 runs, 2 assertions, 0 failures", output end end @@ -118,7 +118,7 @@ module ApplicationTests assert_match "FooMailerTest", output assert_match "BarControllerTest", output assert_match "BazFunctionalTest", output - assert_match "3 tests, 3 assertions, 0 failures", output + assert_match "3 runs, 3 assertions, 0 failures", output end end @@ -127,7 +127,7 @@ module ApplicationTests create_test_file :models, 'foo' run_test_integration_command.tap do |output| assert_match "FooIntegration", output - assert_match "1 tests, 1 assertions, 0 failures", output + assert_match "1 runs, 1 assertions, 0 failures", output end end @@ -136,7 +136,7 @@ module ApplicationTests suites.each { |suite| create_test_file suite, "foo_#{suite}" } run_test_command('') .tap do |output| suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output } - assert_match "7 tests, 7 assertions, 0 failures", output + assert_match "7 runs, 7 assertions, 0 failures", output end end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index ac71fb58843..32c7612a8fb 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -168,14 +168,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase run_generator FileUtils.cd destination_root quietly { system 'bundle install' } - assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) + assert_match(/1 runs, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_ensure_that_tests_works_in_full_mode run_generator [destination_root, "--full", "--skip_active_record"] FileUtils.cd destination_root quietly { system 'bundle install' } - assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) + assert_match(/1 runs, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_ensure_that_migration_tasks_work_with_mountable_option From 0809c09c342d749ca07100cc04ff1d336a68b1fb Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 8 May 2013 16:44:05 -0700 Subject: [PATCH 2/3] tweak dependencies --- Gemfile | 2 +- activesupport/activesupport.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 661ef25a57c..958249a7c9b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' gemspec -gem 'mocha', '~> 0.13.0', require: false +gem 'mocha', git: 'https://github.com/freerange/mocha', require: false gem 'rack-cache', '~> 1.2' gem 'bcrypt-ruby', '~> 3.0.0' gem 'jquery-rails', '~> 2.2.0' diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index b46a331f6ab..b085d89adf2 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -23,6 +23,6 @@ Gem::Specification.new do |s| s.add_dependency('i18n', '~> 0.6', '>= 0.6.4') s.add_dependency 'multi_json', '~> 1.3' s.add_dependency 'tzinfo', '~> 0.3.37' - s.add_dependency 'minitest', '~> 4.2' + s.add_dependency 'minitest', '~> 5.0' s.add_dependency 'thread_safe','~> 0.1' end From de4dcacc200f9bfa79f3c2e13b2091e3d5262f6d Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 9 May 2013 01:50:56 -0700 Subject: [PATCH 3/3] oops. I should have only required minitest, not minitets/autorun. muscle memory. --- activesupport/lib/active_support/testing/autorun.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/testing/autorun.rb b/activesupport/lib/active_support/testing/autorun.rb index 45d8193abbc..5aa5f46310c 100644 --- a/activesupport/lib/active_support/testing/autorun.rb +++ b/activesupport/lib/active_support/testing/autorun.rb @@ -1,5 +1,5 @@ gem 'minitest' -require 'minitest/autorun' +require 'minitest' Minitest.autorun