Class: RuboCop::Cop::Minitest::AssertSilent

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/minitest/assert_silent.rb

Overview

Enforces the test to use ‘assert_silent { … }` instead of using `assert_output(”, ”) { … }`.

Examples:

# bad
assert_output('', '') { puts object.do_something }

# good
assert_silent { puts object.do_something }

Constant Summary collapse

MSG =
'Prefer using `assert_silent`.'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/minitest/assert_silent.rb', line 29

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  return unless assert_silent_candidate?(node)

  send_node = node.send_node

  add_offense(send_node) do |corrector|
    corrector.replace(send_node, 'assert_silent')
  end
end