Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop RSpec/EmptyExampleGroup customization #1007

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 1 addition & 40 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions lib/rubocop/cop/rspec/empty_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,31 +35,6 @@ module RSpec
# describe Bacon do
# pending 'will add tests later'
# end
#
# @example configuration
#
# # .rubocop.yml
# # RSpec/EmptyExampleGroup:
# # CustomIncludeMethods:
pirj marked this conversation as resolved.
Show resolved Hide resolved
# # - 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.'

Expand Down Expand Up @@ -99,7 +72,6 @@ class EmptyExampleGroup < Base
'{#Examples.all #ExampleGroups.all #Includes.all}'
)}
#{send_pattern('{#Examples.all #Includes.all}')}
(send nil? #custom_include? ...)
}
PATTERN

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/rspec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions spec/rubocop/cop/rspec/empty_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down