Class: RuboCop::Cop::Minitest::UnspecifiedException

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/minitest/unspecified_exception.rb

Overview

Checks for a specified error in ‘assert_raises`.

Examples:

# bad
assert_raises { raise FooException }
assert_raises('This should have raised') { raise FooException }

# good
assert_raises(FooException) { raise FooException }
assert_raises(FooException, 'This should have raised') { raise FooException }

Constant Summary collapse

MSG =
'Specify the exception being captured.'

Instance Method Summary collapse

Instance Method Details

#on_block(block_node) ⇒ Object



20
21
22
23
24
25
# File 'lib/rubocop/cop/minitest/unspecified_exception.rb', line 20

def on_block(block_node)
  node = block_node.send_node
  return unless node.method?(:assert_raises)

  add_offense(node) if unspecified_exception?(node)
end