class RuboCop::Cop::Minitest::DuplicateTestRun
end
end
def test_parent
end
def test_child
class ChildTest
end
class ParentTest < Minitest::Test
# good
end
end
def test_child
class ChildTest < Minitest::Test
end
end
def test_parent
class ParentTest < Minitest::Test
# good
end
end
def test_child
class ChildTest < ParentTest
end
end
def test_parent # it will run this test twice.
class ParentTest < Minitest::Test
# bad
@example
This cop will add an offense to the Child class in such a case.
This cop detects when there are two tests classes, one inherits from the other, and both have tests methods.
it will also inherit its methods causing Minitest to run the parent’s tests methods twice.
If a Minitest class inherits from another class,
def on_class(class_node)
def on_class(class_node) return unless test_class?(class_node) return unless test_methods?(class_node) return unless parent_class_has_test_methods?(class_node) message = format(MSG) add_offense(class_node, message: message) end
def parent_class_has_test_methods?(class_node)
def parent_class_has_test_methods?(class_node) parent_class = class_node.parent_class return false unless (class_node_parent = class_node.parent) parent_class_node = class_node_parent.each_child_node(:class).detect do |klass| klass.identifier == parent_class end return false unless parent_class_node test_methods?(parent_class_node) end
def test_methods?(class_node)
def test_methods?(class_node) test_cases(class_node).size.positive? end