Class: RuboCop::Cop::Minitest::ReturnInTestMethod

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RuboCop::Cop::MinitestExplorationHelpers
Defined in:
lib/rubocop/cop/minitest/return_in_test_method.rb

Overview

Enforces the use of ‘skip` instead of `return` in test methods.

Examples:

# bad
def test_something
  return if condition?
  assert_equal(42, something)
end

# good
def test_something
  skip if condition?
  assert_equal(42, something)
end

Constant Summary collapse

MSG =
'Use `skip` instead of `return`.'

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_return(node) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/minitest/return_in_test_method.rb', line 27

def on_return(node)
  return unless node.ancestors.any? { |parent| test_case?(parent) }
  return if inside_block?(node)

  add_offense(node) do |corrector|
    corrector.replace(node, 'skip')
  end
end