Class: RuboCop::Cop::Minitest::UnreachableAssertion
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::UnreachableAssertion
- Includes:
- RuboCop::Cop::MinitestExplorationHelpers
- Defined in:
- lib/rubocop/cop/minitest/unreachable_assertion.rb
Overview
Checks for assert_raises has an assertion method at
the bottom of block because the assertion will be never reached.
Constant Summary collapse
- MSG =
'Unreachable `%<assertion_method>s` detected.'
Constants included from RuboCop::Cop::MinitestExplorationHelpers
RuboCop::Cop::MinitestExplorationHelpers::ASSERTION_PREFIXES, RuboCop::Cop::MinitestExplorationHelpers::BLOCK_MATCHERS, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS_IN_ORDER, RuboCop::Cop::MinitestExplorationHelpers::MATCHER_METHODS, RuboCop::Cop::MinitestExplorationHelpers::VALUE_MATCHERS
Instance Method Summary collapse
-
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler.
Instance Method Details
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
28 29 30 31 32 33 34 35 36 |
# File 'lib/rubocop/cop/minitest/unreachable_assertion.rb', line 28 def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler return unless node.method?(:assert_raises) && (body = node.body) last_node = body.begin_type? ? body.children.last : body return unless last_node.send_type? return if !assertion_method?(last_node) || !body.begin_type? add_offense(last_node, message: format(MSG, assertion_method: last_node.method_name)) end |