mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #10527 from zenspider/squishy_minitest5
Squishy minitest5
This commit is contained in:
commit
9fef7c8dc9
13 changed files with 50 additions and 146 deletions
2
Gemfile
2
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'
|
||||
|
|
|
@ -211,7 +211,9 @@ module ActionView
|
|||
alias_method :_view, :view
|
||||
|
||||
INTERNAL_IVARS = [
|
||||
:@__name__,
|
||||
:@NAME,
|
||||
:@failures,
|
||||
:@assertions,
|
||||
:@__io__,
|
||||
:@_assertion_wrapped,
|
||||
:@_assertions,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency('i18n', '~> 0.6', '>= 0.6.4')
|
||||
s.add_dependency 'json', '~> 1.7'
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
gem 'minitest'
|
||||
|
||||
require 'minitest/unit'
|
||||
require 'minitest'
|
||||
|
||||
MiniTest::Unit.autorun
|
||||
Minitest.autorun
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue