From ac38248609badc569acc0448ccc8b08f0f5e19c1 Mon Sep 17 00:00:00 2001 From: Jason Robinaugh Date: Wed, 27 Dec 2023 11:10:18 -0500 Subject: [PATCH] Ensure PendingWithoutReason can detect violations inside shared groups --- CHANGELOG.md | 2 ++ .../cop/rspec/pending_without_reason.rb | 2 +- .../cop/rspec/pending_without_reason_spec.rb | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 360677133..dd8673b9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add new `RSpec/RedundantPredicateMatcher` cop. ([@ydah]) - Add support for correcting "it will" (future tense) for `RSpec/ExampleWording`. ([@jdufresne]) - Add new `RSpec/RemoveConst` cop. ([@swelther]) +- Ensure `PendingWithoutReason` can detect violations inside shared groups. ([@robinaugh]) ## 2.25.0 (2023-10-27) @@ -902,6 +903,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features. [@rafix02]: https://github.com/Rafix02 [@redross]: https://github.com/redross [@renanborgescampos]: https://github.com/renanborgescampos +[@robinaugh]: https://github.com/robinaugh [@robotdana]: https://github.com/robotdana [@rolfschmidt]: https://github.com/rolfschmidt [@rrosenblum]: https://github.com/rrosenblum diff --git a/lib/rubocop/cop/rspec/pending_without_reason.rb b/lib/rubocop/cop/rspec/pending_without_reason.rb index bf57636a9..c710703a9 100644 --- a/lib/rubocop/cop/rspec/pending_without_reason.rb +++ b/lib/rubocop/cop/rspec/pending_without_reason.rb @@ -103,7 +103,7 @@ def on_send(node) on_pending_by_metadata(node) return unless (parent = parent_node(node)) - if example_group?(parent) || block_node_example_group?(node) + if spec_group?(parent) || block_node_example_group?(node) on_skipped_by_example_method(node) on_skipped_by_example_group_method(node) elsif example?(parent) diff --git a/spec/rubocop/cop/rspec/pending_without_reason_spec.rb b/spec/rubocop/cop/rspec/pending_without_reason_spec.rb index 89669ba8d..9e678e859 100644 --- a/spec/rubocop/cop/rspec/pending_without_reason_spec.rb +++ b/spec/rubocop/cop/rspec/pending_without_reason_spec.rb @@ -29,6 +29,19 @@ end end + context 'when pending/skip has a reason inside a shared example group' do + it 'registers no offense' do + expect_no_offenses(<<~RUBY) + RSpec.describe Foo do + shared_examples 'something' do + pending 'does something' + skip 'does something' + end + end + RUBY + end + end + context 'when pending/skip by metadata on example with reason' do it 'registers no offense' do expect_no_offenses(<<~RUBY) @@ -402,4 +415,18 @@ RUBY end end + + context 'when skipped inside a shared example group' do + it 'registers offense' do + expect_offense(<<~RUBY) + RSpec.describe Foo do + shared_examples 'something' do + xit 'something' do + ^^^^^^^^^^^^^^^ Give the reason for xit. + end + end + end + RUBY + end + end end