From 59632d9c68c99327ed87a8e96b8cd7cc369580d1 Mon Sep 17 00:00:00 2001 From: Tietew Date: Mon, 12 Oct 2020 17:25:30 +0900 Subject: [PATCH] Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s). --- CHANGELOG.md | 3 +- .../cop/rspec/repeated_example_group_body.rb | 2 +- .../rspec/repeated_example_group_body_spec.rb | 44 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30ce30b0a..b06a27936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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 diff --git a/lib/rubocop/cop/rspec/repeated_example_group_body.rb b/lib/rubocop/cop/rspec/repeated_example_group_body.rb index d419b76c0..596d6d61c 100644 --- a/lib/rubocop/cop/rspec/repeated_example_group_body.rb +++ b/lib/rubocop/cop/rspec/repeated_example_group_body.rb @@ -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) diff --git a/spec/rubocop/cop/rspec/repeated_example_group_body_spec.rb b/spec/rubocop/cop/rspec/repeated_example_group_body_spec.rb index 5fab4cd72..d76585002 100644 --- a/spec/rubocop/cop/rspec/repeated_example_group_body_spec.rb +++ b/spec/rubocop/cop/rspec/repeated_example_group_body_spec.rb @@ -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