Skip to content

Commit 2e3ed04

Browse files
committed
Remove customization from RSpec/EmptyExampleGroup
The customization is now made via .rubocop.yml configuration, i.e.: RSpec: Language: Includes: Example: - it_has_special_behavior
1 parent 13cb62f commit 2e3ed04

File tree

6 files changed

+7
-82
lines changed

6 files changed

+7
-82
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Retire `RSpec/InvalidPredicateMatcher` cop. ([@pirj][])
77
* Remove the code responsible for filtering files to inspect. ([@pirj][])
88
* Make RSpec language elements configurable. ([@sl4vr][])
9+
* Remove `CustomIncludeMethods` `RSpec/EmptyExampleGroup` option in favour of the new RSpec DSL configuration. ([@pirj][])
910

1011
## 2.0.0.pre (2020-10-22)
1112

config/default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ RSpec/Dialect:
207207
RSpec/EmptyExampleGroup:
208208
Description: Checks if an example group does not include any tests.
209209
Enabled: true
210-
CustomIncludeMethods: []
211210
VersionAdded: '1.7'
211+
VersionChanged: '2.0'
212212
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup
213213

214214
RSpec/EmptyHook:

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,11 @@ end
729729
| Yes
730730
| No
731731
| 1.7
732-
| -
732+
| 2.0
733733
|===
734734

735735
Checks if an example group does not include any tests.
736736

737-
This cop is configurable using the `CustomIncludeMethods` option
738-
739737
=== Examples
740738

741739
==== usage
@@ -772,43 +770,6 @@ describe Bacon do
772770
end
773771
----
774772

775-
==== configuration
776-
777-
[source,ruby]
778-
----
779-
# .rubocop.yml
780-
# RSpec/EmptyExampleGroup:
781-
# CustomIncludeMethods:
782-
# - include_tests
783-
784-
# spec_helper.rb
785-
RSpec.configure do |config|
786-
config.alias_it_behaves_like_to(:include_tests)
787-
end
788-
789-
# bacon_spec.rb
790-
describe Bacon do
791-
let(:bacon) { Bacon.new(chunkiness) }
792-
let(:chunkiness) { false }
793-
794-
context 'extra chunky' do # not flagged by rubocop
795-
let(:chunkiness) { true }
796-
797-
include_tests 'shared tests'
798-
end
799-
end
800-
----
801-
802-
=== Configurable attributes
803-
804-
|===
805-
| Name | Default value | Configurable values
806-
807-
| CustomIncludeMethods
808-
| `[]`
809-
| Array
810-
|===
811-
812773
=== References
813774

814775
* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup

lib/rubocop/cop/rspec/empty_example_group.rb

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module Cop
55
module RSpec
66
# Checks if an example group does not include any tests.
77
#
8-
# This cop is configurable using the `CustomIncludeMethods` option
9-
#
108
# @example usage
119
#
1210
# # bad
@@ -37,31 +35,6 @@ module RSpec
3735
# describe Bacon do
3836
# pending 'will add tests later'
3937
# end
40-
#
41-
# @example configuration
42-
#
43-
# # .rubocop.yml
44-
# # RSpec/EmptyExampleGroup:
45-
# # CustomIncludeMethods:
46-
# # - include_tests
47-
#
48-
# # spec_helper.rb
49-
# RSpec.configure do |config|
50-
# config.alias_it_behaves_like_to(:include_tests)
51-
# end
52-
#
53-
# # bacon_spec.rb
54-
# describe Bacon do
55-
# let(:bacon) { Bacon.new(chunkiness) }
56-
# let(:chunkiness) { false }
57-
#
58-
# context 'extra chunky' do # not flagged by rubocop
59-
# let(:chunkiness) { true }
60-
#
61-
# include_tests 'shared tests'
62-
# end
63-
# end
64-
#
6538
class EmptyExampleGroup < Base
6639
MSG = 'Empty example group detected.'
6740

@@ -99,7 +72,6 @@ class EmptyExampleGroup < Base
9972
'{#Examples.all #ExampleGroups.all #Includes.all}'
10073
)}
10174
#{send_pattern('{#Examples.all #Includes.all}')}
102-
(send nil? #custom_include? ...)
10375
}
10476
PATTERN
10577

@@ -191,16 +163,6 @@ def conditionals_with_examples?(body)
191163
def examples_in_branches?(if_node)
192164
if_node.branches.any? { |branch| examples?(branch) }
193165
end
194-
195-
def custom_include?(method_name)
196-
custom_include_methods.include?(method_name)
197-
end
198-
199-
def custom_include_methods
200-
cop_config
201-
.fetch('CustomIncludeMethods', [])
202-
.map(&:to_sym)
203-
end
204166
end
205167
end
206168
end

spec/rubocop/cop/rspec/base_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def on_block(node)
118118

119119
context 'when `epic` is set as an alias to example group' do
120120
before do
121-
other_cops['RSpec']['Language']['ExampleGroups']['Regular']
121+
other_cops.dig('RSpec', 'Language', 'ExampleGroups', 'Regular')
122122
.push('epic')
123123
end
124124

spec/rubocop/cop/rspec/empty_example_group_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@
268268
end
269269

270270
context 'when a custom include method is specified' do
271-
let(:cop_config) do
272-
{ 'CustomIncludeMethods' => %w[it_has_special_behavior] }
271+
before do
272+
other_cops.dig('RSpec', 'Language', 'Includes', 'Examples')
273+
.push('it_has_special_behavior')
273274
end
274275

275276
it 'ignores an empty example group with a custom include' do

0 commit comments

Comments
 (0)