diff --git a/lib/rubocop/cop/rspec/unspecified_exception.rb b/lib/rubocop/cop/rspec/unspecified_exception.rb index 30d4c49af..e7d90fec1 100644 --- a/lib/rubocop/cop/rspec/unspecified_exception.rb +++ b/lib/rubocop/cop/rspec/unspecified_exception.rb @@ -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 diff --git a/spec/rubocop/cop/rspec/unspecified_exception_spec.rb b/spec/rubocop/cop/rspec/unspecified_exception_spec.rb index 8c41e6b30..65034a8cd 100644 --- a/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +++ b/spec/rubocop/cop/rspec/unspecified_exception_spec.rb @@ -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