Class: RuboCop::Cop::Minitest::AssertRaisesCompoundBody

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

Overview

Enforces the block body of ‘assert_raises { … }` to be reduced to only the raising code.

Examples:

# bad
assert_raises(MyError) do
  foo
  bar
end

# good
assert_raises(MyError) do
  foo
end

# good
assert_raises(MyError) do
  foo do
    bar
    baz
  end
end

Constant Summary collapse

MSG =
'Reduce `assert_raises` block body to contain only the raising code.'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



31
32
33
34
35
# File 'lib/rubocop/cop/minitest/assert_raises_compound_body.rb', line 31

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  return unless node.method?(:assert_raises) && multi_statement_begin?(node.body)

  add_offense(node)
end