Skip to content

Commit

Permalink
Fix default config for sub-departments
Browse files Browse the repository at this point in the history
It turns out that the default config does not apply for sub-departments.
It is weird on many levels:
 - RSpec DSL configuration didn't work
 - - RSpec DSL doesn't work as intended anyway #1126
 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config
 - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined

Still, I believe having `Include` to work correctly is the most important.

fixes #1160
  • Loading branch information
pirj committed Oct 5, 2021
1 parent e9c1f51 commit ed894a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@
* Add new `RSpec/IdenticalEqualityAssertion` cop. ([@tejasbubane][])
* Add `RSpec/Rails/AvoidSetupHook` cop. ([@paydaylight][])
* Fix false negative in `RSpec/ExpectChange` cop with block style and chained method call. ([@tejasbubane][])
* Fix `Include` configuration for sub-departments. ([@pirj][])

## 2.3.0 (2021-04-28)

Expand Down
19 changes: 17 additions & 2 deletions config/default.yml
@@ -1,10 +1,10 @@
---
RSpec:
Enabled: true
Include:
Include: &1
- "**/*_spec.rb"
- "**/spec/**/*"
Language:
Language: &2
inherit_mode:
merge:
- Expectations
Expand Down Expand Up @@ -745,6 +745,11 @@ RSpec/Yield:
VersionAdded: '1.32'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Yield

RSpec/Capybara:
Enabled: true
Include: *1
Language: *2

RSpec/Capybara/CurrentPathExpectation:
Description: Checks that no expectations are set on Capybara's `current_path`.
Enabled: true
Expand All @@ -767,6 +772,11 @@ RSpec/Capybara/VisibilityMatcher:
VersionChanged: '2.0'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher

RSpec/FactoryBot:
Enabled: true
Include: *1
Language: *2

RSpec/FactoryBot/AttributeDefinedStatically:
Description: Always declare attribute values as blocks.
Enabled: true
Expand Down Expand Up @@ -806,6 +816,11 @@ RSpec/FactoryBot/FactoryClassName:
VersionChanged: '2.0'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName

RSpec/Rails:
Enabled: true
Include: *1
Language: *2

RSpec/Rails/AvoidSetupHook:
Description: Checks that tests use RSpec `before` hook over Rails `setup` method.
Enabled: pending
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/rspec/config_formatter.rb
Expand Up @@ -7,6 +7,7 @@ module RSpec
# Builds a YAML config file from two config hashes
class ConfigFormatter
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
STYLE_GUIDE_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'

def initialize(config, descriptions)
Expand All @@ -24,6 +25,8 @@ def dump

def unified_config
cops.each_with_object(config.dup) do |cop, unified|
next if SUBDEPARTMENTS.include?(cop)

unified[cop] = config.fetch(cop)
.merge(descriptions.fetch(cop))
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
Expand Down
2 changes: 1 addition & 1 deletion spec/project/default_config_spec.rb
Expand Up @@ -29,7 +29,7 @@
end

let(:config_keys) do
cop_names + %w[RSpec]
cop_names + %w[RSpec RSpec/Capybara RSpec/FactoryBot RSpec/Rails]
end

def cop_configuration(config_key)
Expand Down

0 comments on commit ed894a0

Please sign in to comment.