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 committed Oct 13, 2020
1 parent 300943e commit 3252c19
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add `IgnoredMetadata` configuration option to `RSpec/DescribeClass`. ([@Rafix02][])
* Fix false positives in `RSpec/EmptyExampleGroup`. ([@pirj][])
* Fix a false positive for `RSpec/EmptyExampleGroup` when example is defined in an `if` branch. ([@koic][])
* Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s). ([@Tietew][])

## 1.43.2 (2020-08-25)

Expand Down Expand Up @@ -565,3 +566,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@biinari]: https://github.com/biinari
[@koic]: https://github.com/koic
[@Rafix02]: https://github.com/Rafix02
[@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 @@ -55,7 +55,7 @@ class RepeatedExampleGroupBody < Base
def_node_matcher :const_arg, '(block (send _ _ $const ...) ...)'

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 @@ -226,6 +226,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) [15]
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 3252c19

Please sign in to comment.