Skip to content

Commit

Permalink
Fix a false positive for RSpec/RepeatedExampleGroupBody when `pendi…
Browse files Browse the repository at this point in the history
…ng` or `skip` have argument(s).
  • Loading branch information
Tietew authored and bquorning committed Apr 28, 2021
1 parent 3538c8f commit 59632d9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
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
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

0 comments on commit 59632d9

Please sign in to comment.