Skip to content

Commit 5d0fbfb

Browse files
committed
Cover and then remove ancestor.send_type? branch in UnspecifiedException
Wraps a non-send type conditional branch around `raise_error` spec
1 parent e80d28c commit 5d0fbfb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/rubocop/cop/rspec/unspecified_exception.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def empty_exception_matcher?(node)
6464
def find_expect_to(node)
6565
node.each_ancestor.find do |ancestor|
6666
break if ancestor.block_type?
67-
next unless ancestor.send_type?
6867

6968
expect_to?(ancestor)
7069
end

spec/rubocop/cop/rspec/unspecified_exception_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,12 @@ def raise_error
254254
}.to raise_exception(StandardError)
255255
RUBY
256256
end
257+
258+
it 'detects even when a non-send node is an ancestor' do
259+
expect_offense(<<~RUBY)
260+
expect { raise 'error' }.to (branch_conditional ? raise_error : handle_exception)
261+
^^^^^^^^^^^ Specify the exception being captured
262+
RUBY
263+
end
257264
end
258265
end

0 commit comments

Comments
 (0)