From 1f48c7b3f4362b2f01e8ad2ae51805c9b831a689 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 27 Sep 2024 08:45:16 +1200 Subject: [PATCH] test: showcase `RSpec/UnspecifiedException` block/chain confusion is fixed --- CHANGELOG.md | 1 + spec/rubocop/cop/rspec/unspecified_exception_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0797ef0a..d1027dc93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Master (Unreleased) - Fix false-positive for `RSpec/UnspecifiedException` when a method is literally named `raise_exception`. ([@aarestad]) +- Fix false-positive for `RSpec/UnspecifiedException` when `not_to raise_error` is used within a block. ([@aarestad], [@G-Rath]) ## 3.0.5 (2024-09-07) diff --git a/spec/rubocop/cop/rspec/unspecified_exception_spec.rb b/spec/rubocop/cop/rspec/unspecified_exception_spec.rb index 2181b24bb..8c41e6b30 100644 --- a/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +++ b/spec/rubocop/cop/rspec/unspecified_exception_spec.rb @@ -223,6 +223,14 @@ def raise_exception RUBY end + it 'does not confuse blocks with chains' do + expect_no_offenses(<<~RUBY) + expect do + expect { foo }.not_to raise_error + end.to change(Foo, :count).by(3) + RUBY + end + it 'allows a subject function to be named raise_exception' do expect_no_offenses(<<~RUBY) def raise_error