class RuboCop::Cop::RSpec::UnspecifiedException
Checks for a specified error in checking raised errors.
Enforces one of an Exception type, a string, or a regular expression to match against the exception message as a parameter to `raise_error`
@example
# bad expect { raise StandardError.new('error') }.to raise_error # good expect { raise StandardError.new('error') }.to raise_error(StandardError) expect { raise StandardError.new('error') }.to raise_error('error') expect { raise StandardError.new('error') }.to raise_error(/err/) expect { do_something }.not_to raise_error
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
block_with_args?(node)
click to toggle source
# File lib/rubocop/cop/rspec/unspecified_exception.rb, line 57 def block_with_args?(node) return unless node&.block_type? node.arguments? end
empty_exception_matcher?(node)
click to toggle source
# File lib/rubocop/cop/rspec/unspecified_exception.rb, line 53 def empty_exception_matcher?(node) empty_raise_error_or_exception(node) && !block_with_args?(node.parent) end
on_send(node)
click to toggle source
# File lib/rubocop/cop/rspec/unspecified_exception.rb, line 47 def on_send(node) return unless empty_exception_matcher?(node) add_offense(node.children.last) end