Skip to content

Commit

Permalink
Merge pull request #1039 from Tietew/pending_with_arguments
Browse files Browse the repository at this point in the history
Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s).
  • Loading branch information
bquorning authored Apr 28, 2021
2 parents 3538c8f + 59632d9 commit d2daba7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d2daba7

Please sign in to comment.