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

Fix a false positive for RSpec/RepeatedExampleGroupBody when pending or skip have argument(s). #1039

Merged
merged 1 commit into from Apr 28, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,8 +4,8 @@

* Allow `RSpec/ContextWording` to accept multi-word prefixes. ([@hosamaly][])
* Drop support for ruby 2.4. ([@bquorning][])

* Add `CountAsOne` configuration option to `RSpec/ExampleLength`. ([@stephannv][])
* Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s). ([@Tietew][])

## 2.2.0 (2021-02-02)

Expand Down Expand Up @@ -610,3 +610,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@dvandersluis]: https://github.com/dvandersluis
[@hosamaly]: https://github.com/hosamaly
[@stephannv]: https://github.com/stephannv
[@Tietew]: https://github.com/Tietew
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/repeated_example_group_body.rb
Expand Up @@ -62,7 +62,7 @@ class RepeatedExampleGroupBody < Base

# @!method skip_or_pending?(node)
def_node_matcher :skip_or_pending?, <<-PATTERN
(block <(send nil? {:skip :pending}) ...>)
(block <(send nil? {:skip :pending} ...) ...>)
PATTERN

def on_begin(node)
Expand Down
44 changes: 44 additions & 0 deletions spec/rubocop/cop/rspec/repeated_example_group_body_spec.rb
Expand Up @@ -224,6 +224,50 @@
RUBY
end

it 'skips `skip` and `pending` statements with arguments' do
expect_no_offenses(<<-RUBY)
describe '#load' do
skip 'storage feature needed'
end

describe '#save' do
skip 'storage feature needed'
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when I look at it, it seems that there's something wrong, and it's the repeated context title.
Do you mind to make them different?
The example with describe '#load' do isn't the best reference, it's a miss.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try update them to clarify use case.


describe '#get_foo' do
pending 'foo feature is broken'
end

describe '#set_foo' do
pending 'foo feature is broken'
end
RUBY
end

it 'registers offense correctly if `skip` and `pending` have block' do
expect_offense(<<-RUBY)
describe '#load' do
^^^^^^^^^^^^^^^^^^^ Repeated describe block body on line(s) [5]
skip { cool_predicate_method }
end

describe '#save' do
^^^^^^^^^^^^^^^^^^^ Repeated describe block body on line(s) [1]
skip { cool_predicate_method }
end

describe '#get_foo' do
^^^^^^^^^^^^^^^^^^^^^^ Repeated describe block body on line(s) [13]
pending { cool_predicate_method }
end

describe '#set_foo' do
^^^^^^^^^^^^^^^^^^^^^^ Repeated describe block body on line(s) [9]
pending { cool_predicate_method }
end
RUBY
end

it 'registers offense correctly if example groups are separated' do
expect_offense(<<-RUBY)
describe 'repeated' do
Expand Down