Skip to content

Commit

Permalink
Ensure PendingWithoutReason can detect violations inside shared groups
Browse files Browse the repository at this point in the history
  • Loading branch information
robinaugh committed Dec 28, 2023
1 parent fb85f88 commit ac38248
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/pending_without_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions spec/rubocop/cop/rspec/pending_without_reason_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit ac38248

Please sign in to comment.