-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
default_config_spec.rb
77 lines (64 loc) · 2.11 KB
/
default_config_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# frozen_string_literal: true
RSpec.describe 'config/default.yml' do
subject(:default_config) do
RuboCop::ConfigLoader.load_file('config/default.yml')
end
let(:namespaces) do
{
'rspec' => 'RSpec',
'capybara' => 'RSpec/Capybara',
'factory_bot' => 'RSpec/FactoryBot',
'rails' => 'RSpec/Rails'
}
end
let(:cop_names) do
glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec',
'{,capybara,factory_bot,rails}', '*.rb')
cop_names =
Pathname.glob(glob).map do |file|
file_name = file.basename('.rb').to_s
cop_name = file_name.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
namespace = namespaces[file.dirname.basename.to_s]
"#{namespace}/#{cop_name}"
end
cop_names - %w[RSpec/Cop RSpec/Base]
end
let(:config_keys) do
cop_names + %w[AllCops]
end
def cop_configuration(config_key)
cop_names.map do |cop_name|
cop_config = default_config[cop_name]
cop_config.fetch(config_key) do
raise "Expected #{cop_name} to have #{config_key} configuration key"
end
end
end
it 'has configuration for all cops' do
expect(default_config.keys).to match_array(config_keys)
end
xit 'sorts configuration keys alphabetically' do
namespaces.each do |_path, prefix|
expected = config_keys.select { |key| key.start_with?(prefix) }.sort
actual = default_config.keys.select { |key| key.start_with?(prefix) }
actual.each_with_index do |key, idx|
expect(key).to eq expected[idx]
end
end
end
it 'has descriptions for all cops' do
expect(cop_configuration('Description')).to all(be_a(String))
end
it 'does not have newlines in cop descriptions' do
cop_configuration('Description').each do |value|
expect(value).not_to include("\n")
end
end
it 'ends every description with a period' do
expect(cop_configuration('Description')).to all(end_with('.'))
end
it 'includes a valid Enabled for every cop' do
expect(cop_configuration('Enabled'))
.to all be(true).or(be(false)).or(eq('pending'))
end
end