Skip to content

Commit

Permalink
Updates to make rails 4 happy with minitest 5:
Browse files Browse the repository at this point in the history
+ 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.
  • Loading branch information
zenspider committed May 7, 2013
1 parent 2291d0b commit 3073c53
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 144 deletions.
4 changes: 3 additions & 1 deletion actionpack/lib/action_view/test_case.rb
Expand Up @@ -211,7 +211,9 @@ def view
alias_method :_view, :view

INTERNAL_IVARS = [
:@__name__,
:@NAME,
:@failures,
:@assertions,
:@__io__,
:@_assertion_wrapped,
:@_assertions,
Expand Down
1 change: 0 additions & 1 deletion activemodel/test/cases/railtie_test.rb
Expand Up @@ -9,7 +9,6 @@ def setup

@app ||= Class.new(::Rails::Application) do
config.eager_load = false
config.logger = Logger.new(STDOUT)
end
end

Expand Down
24 changes: 21 additions & 3 deletions activesupport/lib/active_support/test_case.rb
Expand Up @@ -16,10 +16,28 @@
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)
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/testing/autorun.rb
@@ -1,5 +1,5 @@
gem 'minitest'

require 'minitest/unit'
require 'minitest/autorun'

MiniTest::Unit.autorun
Minitest.autorun
17 changes: 6 additions & 11 deletions activesupport/lib/active_support/testing/isolation.rb
Expand Up @@ -72,16 +72,12 @@ def _run_class_setup # class setup method should only happen in parent
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
Expand All @@ -90,9 +86,8 @@ def run_in_isolation(&blk)

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

Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/testing/tagged_logging.rb
Expand Up @@ -7,7 +7,7 @@ module TaggedLogging #:nodoc:

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
Expand Down
110 changes: 0 additions & 110 deletions activesupport/test/test_case_test.rb
Expand Up @@ -2,116 +2,6 @@

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"
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/test_test.rb
Expand Up @@ -201,6 +201,6 @@ def before_setup
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
4 changes: 2 additions & 2 deletions railties/test/application/rake_test.rb
Expand Up @@ -214,7 +214,7 @@ def test_scaffold_tests_pass_by_default
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

Expand All @@ -224,7 +224,7 @@ def test_scaffold_with_references_columns_tests_pass_by_default
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

Expand Down
20 changes: 10 additions & 10 deletions railties/test/application/test_runner_test.rb
Expand Up @@ -32,13 +32,13 @@ def test_env
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
Expand All @@ -59,7 +59,7 @@ def test_run_models
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

Expand All @@ -70,7 +70,7 @@ def test_run_helpers
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

Expand All @@ -83,7 +83,7 @@ def test_run_units
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

Expand All @@ -94,7 +94,7 @@ def test_run_controllers
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

Expand All @@ -105,7 +105,7 @@ def test_run_mailers
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

Expand All @@ -118,7 +118,7 @@ def test_run_functionals
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

Expand All @@ -127,7 +127,7 @@ def test_run_integration
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

Expand All @@ -136,7 +136,7 @@ def test_run_all_suites
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

Expand Down
4 changes: 2 additions & 2 deletions railties/test/generators/plugin_new_generator_test.rb
Expand Up @@ -168,14 +168,14 @@ def test_ensure_that_tests_work
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
Expand Down

0 comments on commit 3073c53

Please sign in to comment.