Skip to content

Commit

Permalink
Cover and then remove ancestor.send_type? branch in `UnspecifiedExc…
Browse files Browse the repository at this point in the history
…eption`

Wraps a non-send type conditional branch around `raise_error` spec
  • Loading branch information
corsonknowles committed Nov 2, 2024
1 parent e80d28c commit 4136dac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/unspecified_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def empty_exception_matcher?(node)
def find_expect_to(node)
node.each_ancestor.find do |ancestor|
break if ancestor.block_type?
next unless ancestor.send_type?

expect_to?(ancestor)
end
Expand Down
13 changes: 4 additions & 9 deletions spec/rubocop/cop/rspec/unspecified_exception_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,10 @@ def raise_error
RUBY
end

it 'allows a subject function to be named raise_error' do
expect_no_offenses(<<~RUBY)
def raise_error
raise StandardError
end
expect {
raise_error
}.to raise_exception(StandardError)
it 'detects even when a non-send node is an ancestor' do
expect_offense(<<~RUBY)
expect { raise 'error' }.to (branch_conditional ? raise_error : handle_exception)
^^^^^^^^^^^ Specify the exception being captured
RUBY
end
end
Expand Down

0 comments on commit 4136dac

Please sign in to comment.