-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
config_store_spec.rb
70 lines (60 loc) · 2.39 KB
/
config_store_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
# frozen_string_literal: true
RSpec.describe RuboCop::ConfigStore do
subject(:config_store) { described_class.new }
before do
allow(RuboCop::ConfigLoader).to receive(:configuration_file_for) do |arg|
# File tree:
# file1
# dir/.rubocop.yml
# dir/file2
# dir/subdir/file3
"#{/dir/.match?(arg) ? 'dir' : '.'}/.rubocop.yml"
end
allow(RuboCop::ConfigLoader)
.to receive(:configuration_from_file) { |arg| arg }
allow(RuboCop::ConfigLoader)
.to receive(:load_file) { |arg| RuboCop::Config.new(arg) }
allow(RuboCop::ConfigLoader)
.to receive(:merge_with_default) { |config| "merged #{config.to_h}" }
allow(RuboCop::ConfigLoader)
.to receive(:default_configuration).and_return('default config')
end
describe '.for' do
it 'always uses config specified in command line' do
config_store.options_config = { options_config: true }
expect(config_store.for('file1')).to eq('merged {:options_config=>true}')
end
context 'when no config specified in command line' do
it 'gets config path and config from cache if available' do
expect(RuboCop::ConfigLoader)
.to receive(:configuration_file_for).with('dir').once
expect(RuboCop::ConfigLoader)
.to receive(:configuration_file_for).with('dir/subdir').once
# The stub returns the same config path for dir and dir/subdir.
expect(RuboCop::ConfigLoader)
.to receive(:configuration_from_file)
.with('dir/.rubocop.yml').once
config_store.for('dir/file2')
config_store.for('dir/file2')
config_store.for('dir/subdir/file3')
end
it 'searches for config path if not available in cache' do
expect(RuboCop::ConfigLoader)
.to receive(:configuration_file_for).once
expect(RuboCop::ConfigLoader)
.to receive(:configuration_from_file).once
config_store.for('file1')
end
context 'when --force-default-config option is specified' do
it 'uses default config without searching for config path' do
expect(RuboCop::ConfigLoader)
.not_to receive(:configuration_file_for)
expect(RuboCop::ConfigLoader)
.not_to receive(:configuration_from_file)
config_store.force_default_config!
expect(config_store.for('file1')).to eq('default config')
end
end
end
end
end