class RuboCop::Cop::Minitest::UnreachableAssertion

This cop checks for `assert_raises` has an assertion method at the bottom of block because the assertion will be never reached.

@example

# bad
assert_raises FooError do
  obj.occur_error
  assert_equal('foo', obj.bar) # Never asserted.
end

# good
assert_raises FooError do
  obj.occur_error
end
assert_equal('foo', obj.bar)

Constants

MSG

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/minitest/unreachable_assertion.rb, line 28
def on_block(node)
  return unless node.method?(:assert_raises) && (body = node.body)

  last_node = body.begin_type? ? body.children.last : body
  return unless last_node.send_type?

  method_name = last_node.method_name
  return unless assertion_method?(method_name)

  add_offense(last_node, message: format(MSG, assertion_method: method_name))
end