Class: RuboCop::Cop::Minitest::MultipleAssertions
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::MultipleAssertions
- Includes:
- RuboCop::Cop::MinitestExplorationHelpers
- Defined in:
- lib/rubocop/cop/minitest/multiple_assertions.rb
Overview
Checks if test cases contain too many assertion calls. If conditional code with assertions is used, the branch with maximum assertions is counted. The maximum allowed assertion calls is configurable.
Constant Summary collapse
- MSG =
'Test case has too many assertions [%<total>d/%<max>d].'
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/minitest/multiple_assertions.rb', line 37 def on_class(class_node) return unless test_class?(class_node) test_cases(class_node).each do |node| assertions_count = assertions_count(node.body) next unless assertions_count > max_assertions self.max = assertions_count = format(MSG, total: assertions_count, max: max_assertions) add_offense(node, message: ) end end |