Skip to content

Commit

Permalink
refactored method checks into a custom assertion. (tenderlove)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 13431]
  • Loading branch information
zenspider committed Jun 11, 2022
1 parent 73692f9 commit 001b19e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ def _count
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

Expand Down Expand Up @@ -777,8 +781,8 @@ def test_it_wont_remove_existing_child_test_methods
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
Expand All @@ -792,14 +796,18 @@ def test_it_wont_add_test_methods_to_children
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 = []
Expand Down Expand Up @@ -872,7 +880,7 @@ def test_bug_dsl_expectations
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

Expand Down Expand Up @@ -921,9 +929,9 @@ def test_structure
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
Expand All @@ -940,8 +948,8 @@ def test_structure_postfix_it
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
Expand Down Expand Up @@ -972,9 +980,9 @@ def test_describe_first_structure
].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
Expand Down

0 comments on commit 001b19e

Please sign in to comment.