Sha256: 72d4b63fb45164ba58801792d0c712f1c3029d10e19617d9bcf8d6136a547200
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Minitest # 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) # class UnreachableAssertion < Base include MinitestExplorationHelpers MSG = 'Unreachable `%<assertion_method>s` detected.' 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? return if !assertion_method?(last_node) || !body.begin_type? add_offense(last_node, message: format(MSG, assertion_method: last_node.method_name)) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems