refactored method checks into a custom assertion. (tenderlove)

[git-p4: depot-paths = "//src/minitest/dev/": change = 13431]
This commit is contained in:
Ryan Davis 2022-06-11 14:03:08 -08:00
parent 73692f9202
commit 001b19ec02
1 changed files with 21 additions and 13 deletions

View File

@ -744,6 +744,10 @@ describe Minitest::Spec, :subject do
end
class TestMetaStatic < Minitest::Test
def assert_method_count expected, klass
assert_equal expected, klass.public_instance_methods.grep(/^test_/).count
end
def test_children
Minitest::Spec.children.clear # prevents parallel run
@ -777,8 +781,8 @@ class TestMetaStatic < Minitest::Test
end
end
assert_equal 1, outer.public_instance_methods.grep(/^test_/).count
assert_equal 1, inner.public_instance_methods.grep(/^test_/).count
assert_method_count 1, outer
assert_method_count 1, inner
end
def test_it_wont_add_test_methods_to_children
@ -792,14 +796,18 @@ class TestMetaStatic < Minitest::Test
end
end
assert_equal 1, outer.public_instance_methods.grep(/^test_/).count
assert_equal 0, inner.public_instance_methods.grep(/^test_/).count
assert_method_count 1, outer
assert_method_count 0, inner
end
end
class TestMeta < MetaMetaMetaTestCase
# do not call parallelize_me! here because specs use register_spec_type globally
def assert_defined_methods expected, klass
assert_equal expected, klass.instance_methods(false).sort.map(&:to_s)
end
def util_structure
y = z = nil
before_list = []
@ -872,7 +880,7 @@ class TestMeta < MetaMetaMetaTestCase
end
end
test_name = spec_class.instance_methods.sort.grep(/test/).first
test_name = spec_class.instance_methods.sort.grep(/test_/).first
spec = spec_class.new test_name
@ -921,9 +929,9 @@ class TestMeta < MetaMetaMetaTestCase
inner_methods2 = inner_methods1 +
%w[test_0002_anonymous test_0003_anonymous]
assert_equal top_methods, x.instance_methods(false).sort.map(&:to_s)
assert_equal inner_methods1, y.instance_methods(false).sort.map(&:to_s)
assert_equal inner_methods2, z.instance_methods(false).sort.map(&:to_s)
assert_defined_methods top_methods, x
assert_defined_methods inner_methods1, y
assert_defined_methods inner_methods2, z
end
def test_structure_postfix_it
@ -940,8 +948,8 @@ class TestMeta < MetaMetaMetaTestCase
it "inner-it" do end
end
assert_equal %w[test_0001_inner-it], y.instance_methods(false).map(&:to_s)
assert_equal %w[test_0001_inner-it], z.instance_methods(false).map(&:to_s)
assert_defined_methods %w[test_0001_inner-it], y
assert_defined_methods %w[test_0001_inner-it], z
end
def test_setup_teardown_behavior
@ -972,9 +980,9 @@ class TestMeta < MetaMetaMetaTestCase
].sort
assert_equal test_methods, [x1, x2]
assert_equal test_methods, x.instance_methods.grep(/^test/).map(&:to_s).sort
assert_equal [], y.instance_methods.grep(/^test/)
assert_equal [], z.instance_methods.grep(/^test/)
assert_defined_methods test_methods, x
assert_defined_methods [], y
assert_defined_methods [], z
end
def test_structure_subclasses