mirror of https://github.com/rails/rails
Merge pull request #10527 from zenspider/squishy_minitest5
Squishy minitest5
This commit is contained in:
commit
9fef7c8dc9
2
Gemfile
2
Gemfile
|
@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
gem 'mocha', '~> 0.13.0', require: false
|
gem 'mocha', git: 'https://github.com/freerange/mocha', require: false
|
||||||
gem 'rack-cache', '~> 1.2'
|
gem 'rack-cache', '~> 1.2'
|
||||||
gem 'bcrypt-ruby', '~> 3.0.0'
|
gem 'bcrypt-ruby', '~> 3.0.0'
|
||||||
gem 'jquery-rails', '~> 2.2.0'
|
gem 'jquery-rails', '~> 2.2.0'
|
||||||
|
|
|
@ -211,7 +211,9 @@ module ActionView
|
||||||
alias_method :_view, :view
|
alias_method :_view, :view
|
||||||
|
|
||||||
INTERNAL_IVARS = [
|
INTERNAL_IVARS = [
|
||||||
:@__name__,
|
:@NAME,
|
||||||
|
:@failures,
|
||||||
|
:@assertions,
|
||||||
:@__io__,
|
:@__io__,
|
||||||
:@_assertion_wrapped,
|
:@_assertion_wrapped,
|
||||||
:@_assertions,
|
:@_assertions,
|
||||||
|
|
|
@ -9,7 +9,6 @@ class RailtieTest < ActiveModel::TestCase
|
||||||
|
|
||||||
@app ||= Class.new(::Rails::Application) do
|
@app ||= Class.new(::Rails::Application) do
|
||||||
config.eager_load = false
|
config.eager_load = false
|
||||||
config.logger = Logger.new(STDOUT)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency('i18n', '~> 0.6', '>= 0.6.4')
|
s.add_dependency('i18n', '~> 0.6', '>= 0.6.4')
|
||||||
s.add_dependency 'json', '~> 1.7'
|
s.add_dependency 'json', '~> 1.7'
|
||||||
s.add_dependency 'tzinfo', '~> 0.3.37'
|
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'
|
s.add_dependency 'thread_safe','~> 0.1'
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,10 +16,28 @@ begin
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
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
|
module ActiveSupport
|
||||||
class TestCase < ::MiniTest::Unit::TestCase
|
class TestCase < ::Minitest::Test
|
||||||
Assertion = MiniTest::Assertion
|
Assertion = Minitest::Assertion
|
||||||
alias_method :method_name, :__name__
|
|
||||||
|
alias_method :method_name, :name
|
||||||
|
|
||||||
$tags = {}
|
$tags = {}
|
||||||
def self.for_tag(tag)
|
def self.for_tag(tag)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
gem 'minitest'
|
gem 'minitest'
|
||||||
|
|
||||||
require 'minitest/unit'
|
require 'minitest'
|
||||||
|
|
||||||
MiniTest::Unit.autorun
|
Minitest.autorun
|
||||||
|
|
|
@ -72,16 +72,12 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(runner)
|
def run
|
||||||
_run_class_setup
|
serialized = run_in_isolation do
|
||||||
|
super
|
||||||
serialized = run_in_isolation do |isolated_runner|
|
|
||||||
super(isolated_runner)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
retval, proxy = Marshal.load(serialized)
|
Marshal.load(serialized)
|
||||||
proxy.__replay__(runner)
|
|
||||||
retval
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Forking
|
module Forking
|
||||||
|
@ -90,9 +86,8 @@ module ActiveSupport
|
||||||
|
|
||||||
pid = fork do
|
pid = fork do
|
||||||
read.close
|
read.close
|
||||||
proxy = ProxyTestResult.new
|
yield
|
||||||
retval = yield proxy
|
write.puts [Marshal.dump(self.dup)].pack("m")
|
||||||
write.puts [Marshal.dump([retval, proxy])].pack("m")
|
|
||||||
exit!
|
exit!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ module ActiveSupport
|
||||||
|
|
||||||
def before_setup
|
def before_setup
|
||||||
if tagged_logger
|
if tagged_logger
|
||||||
heading = "#{self.class}: #{__name__}"
|
heading = "#{self.class}: #{name}"
|
||||||
divider = '-' * heading.size
|
divider = '-' * heading.size
|
||||||
tagged_logger.info divider
|
tagged_logger.info divider
|
||||||
tagged_logger.info heading
|
tagged_logger.info heading
|
||||||
|
|
|
@ -2,116 +2,6 @@ require 'abstract_unit'
|
||||||
|
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
class TestCaseTest < ActiveSupport::TestCase
|
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
|
def test_pending_deprecation
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
pending "should use #skip instead"
|
pending "should use #skip instead"
|
||||||
|
|
|
@ -201,6 +201,6 @@ class TestCaseTaggedLoggingTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_logs_tagged_with_current_test_case
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -214,7 +214,7 @@ module ApplicationTests
|
||||||
bundle exec rake db:migrate db:test:clone test`
|
bundle exec rake db:migrate db:test:clone test`
|
||||||
end
|
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)
|
assert_no_match(/Errors running/, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ module ApplicationTests
|
||||||
bundle exec rake db:migrate db:test:clone test`
|
bundle exec rake db:migrate db:test:clone test`
|
||||||
end
|
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)
|
assert_no_match(/Errors running/, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ module ApplicationTests
|
||||||
def test_run_single_file
|
def test_run_single_file
|
||||||
create_test_file :models, 'foo'
|
create_test_file :models, 'foo'
|
||||||
create_test_file :models, 'bar'
|
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
|
end
|
||||||
|
|
||||||
def test_run_multiple_files
|
def test_run_multiple_files
|
||||||
create_test_file :models, 'foo'
|
create_test_file :models, 'foo'
|
||||||
create_test_file :models, 'bar'
|
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
|
end
|
||||||
|
|
||||||
def test_run_file_with_syntax_error
|
def test_run_file_with_syntax_error
|
||||||
|
@ -59,7 +59,7 @@ module ApplicationTests
|
||||||
run_test_models_command.tap do |output|
|
run_test_models_command.tap do |output|
|
||||||
assert_match "FooTest", output
|
assert_match "FooTest", output
|
||||||
assert_match "BarTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ module ApplicationTests
|
||||||
run_test_helpers_command.tap do |output|
|
run_test_helpers_command.tap do |output|
|
||||||
assert_match "FooHelperTest", output
|
assert_match "FooHelperTest", output
|
||||||
assert_match "BarHelperTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ module ApplicationTests
|
||||||
assert_match "FooTest", output
|
assert_match "FooTest", output
|
||||||
assert_match "BarHelperTest", output
|
assert_match "BarHelperTest", output
|
||||||
assert_match "BazUnitTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ module ApplicationTests
|
||||||
run_test_controllers_command.tap do |output|
|
run_test_controllers_command.tap do |output|
|
||||||
assert_match "FooControllerTest", output
|
assert_match "FooControllerTest", output
|
||||||
assert_match "BarControllerTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ module ApplicationTests
|
||||||
run_test_mailers_command.tap do |output|
|
run_test_mailers_command.tap do |output|
|
||||||
assert_match "FooMailerTest", output
|
assert_match "FooMailerTest", output
|
||||||
assert_match "BarMailerTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ module ApplicationTests
|
||||||
assert_match "FooMailerTest", output
|
assert_match "FooMailerTest", output
|
||||||
assert_match "BarControllerTest", output
|
assert_match "BarControllerTest", output
|
||||||
assert_match "BazFunctionalTest", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ module ApplicationTests
|
||||||
create_test_file :models, 'foo'
|
create_test_file :models, 'foo'
|
||||||
run_test_integration_command.tap do |output|
|
run_test_integration_command.tap do |output|
|
||||||
assert_match "FooIntegration", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ module ApplicationTests
|
||||||
suites.each { |suite| create_test_file suite, "foo_#{suite}" }
|
suites.each { |suite| create_test_file suite, "foo_#{suite}" }
|
||||||
run_test_command('') .tap do |output|
|
run_test_command('') .tap do |output|
|
||||||
suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -168,14 +168,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
||||||
run_generator
|
run_generator
|
||||||
FileUtils.cd destination_root
|
FileUtils.cd destination_root
|
||||||
quietly { system 'bundle install' }
|
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
|
end
|
||||||
|
|
||||||
def test_ensure_that_tests_works_in_full_mode
|
def test_ensure_that_tests_works_in_full_mode
|
||||||
run_generator [destination_root, "--full", "--skip_active_record"]
|
run_generator [destination_root, "--full", "--skip_active_record"]
|
||||||
FileUtils.cd destination_root
|
FileUtils.cd destination_root
|
||||||
quietly { system 'bundle install' }
|
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
|
end
|
||||||
|
|
||||||
def test_ensure_that_migration_tasks_work_with_mountable_option
|
def test_ensure_that_migration_tasks_work_with_mountable_option
|
||||||
|
|
Loading…
Reference in New Issue