Class: RuboCop::Cop::Minitest::DuplicateTestRun
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::DuplicateTestRun
- Includes:
- RuboCop::Cop::MinitestExplorationHelpers
- Defined in:
- lib/rubocop/cop/minitest/duplicate_test_run.rb
Overview
If a Minitest class inherits from another class, it will also inherit its methods causing Minitest to run the parent’s tests methods twice.
This cop detects when there are two tests classes, one inherits from the other, and both have tests methods. This cop will add an offense to the Child class in such a case.
Constant Summary collapse
- MSG =
"Subclasses with test methods causes the parent' tests to run them twice."
Constants included from RuboCop::Cop::MinitestExplorationHelpers
RuboCop::Cop::MinitestExplorationHelpers::ASSERTION_PREFIXES, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS_IN_ORDER
Instance Method Summary collapse
Instance Method Details
#on_class(class_node) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/rubocop/cop/minitest/duplicate_test_run.rb', line 53 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) = format(MSG) add_offense(class_node, message: ) end |