Skip to content

Commit

Permalink
Merge pull request #1991 from corsonknowles/cover_one_more_branch
Browse files Browse the repository at this point in the history
Cover and then remove `ancestor.send_type?` branch in `UnspecifiedException`
  • Loading branch information
bquorning authored Nov 2, 2024
2 parents 00b6c03 + 5d0fbfb commit f96f5c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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
7 changes: 7 additions & 0 deletions spec/rubocop/cop/rspec/unspecified_exception_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,12 @@ def raise_error
}.to raise_exception(StandardError)
RUBY
end

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
end

0 comments on commit f96f5c5

Please sign in to comment.