class RuboCop::Cop::RSpec::UnspecifiedException
expect { do_something }.not_to raise_error
}.to raise_error(/err/)
raise StandardError.new(‘error’)
expect {
}.to raise_error(‘error’)
raise StandardError.new(‘error’)
expect {
}.to raise_error(StandardError)
raise StandardError.new(‘error’)
expect {
# good
}.to raise_error
raise StandardError.new(‘error’)
expect {
# bad
@example
to ‘raise_error`
expression to match against the exception message as a parameter
Enforces one of an Exception type, a string, or a regular
Checks for a specified error in checking raised errors.
def empty_exception_matcher?(node)
def empty_exception_matcher?(node) return false if node.arguments? || node.block_literal? expect_to = find_expect_to(node) return false unless expect_to return false if expect_to.block_node&.arguments? true end
def find_expect_to(node)
def find_expect_to(node) node.each_ancestor.find do |ancestor| break if ancestor.block_type? expect_to?(ancestor) end end
def on_send(node)
def on_send(node) return unless empty_exception_matcher?(node) add_offense(node) end