Skip to content

Commit e461bad

Browse files
committed
Improve spec branch coverage for ConfigFormatter
AMENDMENTS was defined as a String, not an Array. And splatting the array into `#gsub` doesn't work if there is more than one element - we would need to use `Regexp.union` instead... but actually I ended up removing AMENDMENTS altogether. All we want to do is to add an extra newline before each cop entry. Only new cop entries starts at the beginning of line, and contains a slash character after the first word. This means we don't need AMENDMENTS at all, and we no longer need the capture in EXTENSION_ROOT_DEPARTMENT.
1 parent 4f85ce5 commit e461bad

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/rubocop/rspec/config_formatter.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ module RuboCop
66
module RSpec
77
# Builds a YAML config file from two config hashes
88
class ConfigFormatter
9-
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
10-
AMENDMENTS = %(Metrics/BlockLength)
9+
EXTENSION_ROOT_DEPARTMENT = %r{^RSpec/}.freeze
1110
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
1211

1312
def initialize(config, descriptions)
@@ -17,8 +16,7 @@ def initialize(config, descriptions)
1716

1817
def dump
1918
YAML.dump(unified_config)
20-
.gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1")
21-
.gsub(*AMENDMENTS, "\n\\0")
19+
.gsub(%r{^\w+/}, "\n\\0")
2220
.gsub(/^(\s+)- /, '\1 - ')
2321
.gsub('"~"', '~')
2422
end
@@ -27,8 +25,6 @@ def dump
2725

2826
def unified_config
2927
cops.each_with_object(config.dup) do |cop, unified|
30-
next if AMENDMENTS.include?(cop)
31-
3228
replace_nil(unified[cop])
3329
unified[cop].merge!(descriptions.fetch(cop))
3430
unified[cop]['Reference'] = reference(cop)

spec/rubocop/rspec/config_formatter_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
'AllCops' => {
99
'Setting' => 'forty two'
1010
},
11+
'Metrics/BlockLength' => {
12+
'Exclude' => [
13+
'**/*_spec.rb',
14+
'**/spec/**/*'
15+
]
16+
},
1117
'RSpec/Foo' => {
1218
'Config' => 2,
1319
'Enabled' => true
@@ -18,6 +24,7 @@
1824
},
1925
'RSpec/Baz' => {
2026
'Enabled' => true,
27+
'NegatedMatcher' => '~',
2128
'StyleGuide' => '#buzz'
2229
}
2330
}
@@ -45,6 +52,11 @@
4552
AllCops:
4653
Setting: forty two
4754
55+
Metrics/BlockLength:
56+
Exclude:
57+
- "**/*_spec.rb"
58+
- "**/spec/**/*"
59+
4860
RSpec/Foo:
4961
Config: 2
5062
Enabled: true
@@ -59,6 +71,7 @@
5971
6072
RSpec/Baz:
6173
Enabled: true
74+
NegatedMatcher: ~
6275
StyleGuide: "#buzz"
6376
Description: Woof
6477
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Baz

0 commit comments

Comments
 (0)