/
config_test.rb
59 lines (44 loc) · 1.63 KB
/
config_test.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
# frozen_string_literal: true
require "test_helper"
require "diffy"
require "rubocop"
require "rake"
class ConfigTest < Minitest::Test
def test_config_is_unchanged
Rake.application.load_rakefile
original_config = "test/fixtures/full_config.yml"
Tempfile.create do |tempfile|
Rake::Task["config:dump"].invoke(tempfile.path)
diff = Diffy::Diff.new(
original_config, tempfile.path, source: "files", context: 5
).to_s
error_message = <<~ERROR
Error: unexpected RuboCop configuration changes were detected.
#{diff}
If these changes are intentional, please update the config dump
by running `bundle exec rake config:dump`.
ERROR
assert(diff.empty?, error_message)
end
end
def test_config_has_no_redundant_entries
config = RuboCop::ConfigLoader.load_file("rubocop.yml")
default_config = RuboCop::ConfigLoader.default_configuration
redundant_config = Hash.new { |hash, key| hash[key] = {} }
# This entry is not a cop.
config.delete("inherit_mode")
config.each do |cop_name, cop_config|
default_cop_config = default_config.fetch(cop_name)
cop_config.each do |key, value|
default_value = default_cop_config[key]
redundant_config[cop_name][key] = value if value == default_value
end
end
flunk(<<~ERROR.chomp) unless redundant_config.empty?
Error: The following config values are the same as the default Rubocop configuration:
#{redundant_config.to_yaml.sub(/\A---\n/, "").chomp}
Please remove these entries from the configuration, as they are unnecessary.
ERROR
end
end
end