Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure PendingWithoutReason can detect violations inside shared groups #1757

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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