From 2e3ed04fe950d0fe3c2533231e63cea8bf0cbe48 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Wed, 19 Aug 2020 18:58:06 +0300 Subject: [PATCH] Remove customization from RSpec/EmptyExampleGroup The customization is now made via .rubocop.yml configuration, i.e.: RSpec: Language: Includes: Example: - it_has_special_behavior --- CHANGELOG.md | 1 + config/default.yml | 2 +- docs/modules/ROOT/pages/cops_rspec.adoc | 41 +------------------ lib/rubocop/cop/rspec/empty_example_group.rb | 38 ----------------- spec/rubocop/cop/rspec/base_spec.rb | 2 +- .../cop/rspec/empty_example_group_spec.rb | 5 ++- 6 files changed, 7 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 789a90dde..873603199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Retire `RSpec/InvalidPredicateMatcher` cop. ([@pirj][]) * Remove the code responsible for filtering files to inspect. ([@pirj][]) * Make RSpec language elements configurable. ([@sl4vr][]) +* Remove `CustomIncludeMethods` `RSpec/EmptyExampleGroup` option in favour of the new RSpec DSL configuration. ([@pirj][]) ## 2.0.0.pre (2020-10-22) diff --git a/config/default.yml b/config/default.yml index 19e5eccc0..129507d6c 100644 --- a/config/default.yml +++ b/config/default.yml @@ -207,8 +207,8 @@ RSpec/Dialect: RSpec/EmptyExampleGroup: Description: Checks if an example group does not include any tests. Enabled: true - CustomIncludeMethods: [] VersionAdded: '1.7' + VersionChanged: '2.0' StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup RSpec/EmptyHook: diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index 98f9bfd1e..e4470e784 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -729,13 +729,11 @@ end | Yes | No | 1.7 -| - +| 2.0 |=== Checks if an example group does not include any tests. -This cop is configurable using the `CustomIncludeMethods` option - === Examples ==== usage @@ -772,43 +770,6 @@ describe Bacon do end ---- -==== configuration - -[source,ruby] ----- -# .rubocop.yml -# RSpec/EmptyExampleGroup: -# CustomIncludeMethods: -# - include_tests - -# spec_helper.rb -RSpec.configure do |config| - config.alias_it_behaves_like_to(:include_tests) -end - -# bacon_spec.rb -describe Bacon do - let(:bacon) { Bacon.new(chunkiness) } - let(:chunkiness) { false } - - context 'extra chunky' do # not flagged by rubocop - let(:chunkiness) { true } - - include_tests 'shared tests' - end -end ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| CustomIncludeMethods -| `[]` -| Array -|=== - === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup diff --git a/lib/rubocop/cop/rspec/empty_example_group.rb b/lib/rubocop/cop/rspec/empty_example_group.rb index 669ecf65b..745e59e2a 100644 --- a/lib/rubocop/cop/rspec/empty_example_group.rb +++ b/lib/rubocop/cop/rspec/empty_example_group.rb @@ -5,8 +5,6 @@ module Cop module RSpec # Checks if an example group does not include any tests. # - # This cop is configurable using the `CustomIncludeMethods` option - # # @example usage # # # bad @@ -37,31 +35,6 @@ module RSpec # describe Bacon do # pending 'will add tests later' # end - # - # @example configuration - # - # # .rubocop.yml - # # RSpec/EmptyExampleGroup: - # # CustomIncludeMethods: - # # - include_tests - # - # # spec_helper.rb - # RSpec.configure do |config| - # config.alias_it_behaves_like_to(:include_tests) - # end - # - # # bacon_spec.rb - # describe Bacon do - # let(:bacon) { Bacon.new(chunkiness) } - # let(:chunkiness) { false } - # - # context 'extra chunky' do # not flagged by rubocop - # let(:chunkiness) { true } - # - # include_tests 'shared tests' - # end - # end - # class EmptyExampleGroup < Base MSG = 'Empty example group detected.' @@ -99,7 +72,6 @@ class EmptyExampleGroup < Base '{#Examples.all #ExampleGroups.all #Includes.all}' )} #{send_pattern('{#Examples.all #Includes.all}')} - (send nil? #custom_include? ...) } PATTERN @@ -191,16 +163,6 @@ def conditionals_with_examples?(body) def examples_in_branches?(if_node) if_node.branches.any? { |branch| examples?(branch) } end - - def custom_include?(method_name) - custom_include_methods.include?(method_name) - end - - def custom_include_methods - cop_config - .fetch('CustomIncludeMethods', []) - .map(&:to_sym) - end end end end diff --git a/spec/rubocop/cop/rspec/base_spec.rb b/spec/rubocop/cop/rspec/base_spec.rb index 97b38b1dc..bec4f5d28 100644 --- a/spec/rubocop/cop/rspec/base_spec.rb +++ b/spec/rubocop/cop/rspec/base_spec.rb @@ -118,7 +118,7 @@ def on_block(node) context 'when `epic` is set as an alias to example group' do before do - other_cops['RSpec']['Language']['ExampleGroups']['Regular'] + other_cops.dig('RSpec', 'Language', 'ExampleGroups', 'Regular') .push('epic') end diff --git a/spec/rubocop/cop/rspec/empty_example_group_spec.rb b/spec/rubocop/cop/rspec/empty_example_group_spec.rb index db83cfbd7..f60c191f0 100644 --- a/spec/rubocop/cop/rspec/empty_example_group_spec.rb +++ b/spec/rubocop/cop/rspec/empty_example_group_spec.rb @@ -268,8 +268,9 @@ end context 'when a custom include method is specified' do - let(:cop_config) do - { 'CustomIncludeMethods' => %w[it_has_special_behavior] } + before do + other_cops.dig('RSpec', 'Language', 'Includes', 'Examples') + .push('it_has_special_behavior') end it 'ignores an empty example group with a custom include' do