|
13 | 13 | end |
14 | 14 |
|
15 | 15 | it 'loads the default config file' do |
16 | | - allow(YAML).to receive(:safe_load_file).with(default_config_file).and_return( |
| 16 | + allow(YAML).to receive(:safe_load_file).with(default_config_file, fallback: {}).and_return( |
17 | 17 | 'rails' => { |
18 | 18 | 'web' => { 'threads' => 4 }, |
19 | 19 | 'grpc' => { 'threads' => 8 }, |
|
29 | 29 | end |
30 | 30 |
|
31 | 31 | it 'uses built-in defaults when the default config file does not exist' do |
32 | | - allow(YAML).to receive(:safe_load_file).with(default_config_file).and_raise(Errno::ENOENT) |
| 32 | + allow(YAML).to receive(:safe_load_file).with(default_config_file, fallback: {}).and_raise(Errno::ENOENT) |
33 | 33 |
|
34 | 34 | expect(described_class.config).to eq(described_class.defaults) |
35 | 35 | end |
|
39 | 39 | configured_files = ' config/base.yml,config/environment.yml, config/runtime.yml ' |
40 | 40 | allow(ENV).to receive(:fetch).with('SAGITTARIUS_CONFIG_FILES', nil) |
41 | 41 | .and_return(configured_files) |
42 | | - allow(YAML).to receive(:safe_load_file).with('config/base.yml').and_return( |
| 42 | + allow(YAML).to receive(:safe_load_file).with('config/base.yml', fallback: {}).and_return( |
43 | 43 | 'rails' => { |
44 | 44 | 'web' => { 'threads' => 4, 'port' => 4000 }, |
45 | 45 | 'grpc' => { 'threads' => 4 }, |
46 | 46 | } |
47 | 47 | ) |
48 | | - allow(YAML).to receive(:safe_load_file).with('config/environment.yml').and_return( |
| 48 | + allow(YAML).to receive(:safe_load_file).with('config/environment.yml', fallback: {}).and_return( |
49 | 49 | 'rails' => { |
50 | 50 | 'web' => { 'threads' => 8 }, |
51 | 51 | 'grpc' => { 'host' => 'environment:50051' }, |
52 | 52 | } |
53 | 53 | ) |
54 | | - allow(YAML).to receive(:safe_load_file).with('config/runtime.yml').and_return( |
| 54 | + allow(YAML).to receive(:safe_load_file).with('config/runtime.yml', fallback: {}).and_return( |
55 | 55 | 'rails' => { |
56 | 56 | 'web' => { 'threads' => 16 }, |
57 | 57 | } |
|
70 | 70 | it 'loads each configured file in order' do |
71 | 71 | described_class.config |
72 | 72 |
|
73 | | - expect(YAML).to have_received(:safe_load_file).ordered.with('config/base.yml') |
74 | | - expect(YAML).to have_received(:safe_load_file).ordered.with('config/environment.yml') |
75 | | - expect(YAML).to have_received(:safe_load_file).ordered.with('config/runtime.yml') |
| 73 | + expect(YAML).to have_received(:safe_load_file).ordered.with('config/base.yml', fallback: {}) |
| 74 | + expect(YAML).to have_received(:safe_load_file).ordered.with('config/environment.yml', fallback: {}) |
| 75 | + expect(YAML).to have_received(:safe_load_file).ordered.with('config/runtime.yml', fallback: {}) |
76 | 76 | end |
77 | 77 |
|
78 | 78 | it 'raises when a configured file does not exist' do |
79 | | - allow(YAML).to receive(:safe_load_file).with('config/environment.yml').and_raise(Errno::ENOENT) |
| 79 | + allow(YAML).to receive(:safe_load_file).with('config/environment.yml', fallback: {}).and_raise(Errno::ENOENT) |
80 | 80 |
|
81 | 81 | expect { described_class.config }.to raise_error(Errno::ENOENT) |
82 | 82 | end |
|
85 | 85 |
|
86 | 86 | describe '.defaults' do |
87 | 87 | it 'matches the example config' do |
88 | | - example_config = YAML.safe_load_file(Rails.root.join('config/sagittarius.example.yml')).deep_symbolize_keys |
| 88 | + example_config = YAML.safe_load_file( |
| 89 | + Rails.root.join('config/sagittarius.example.yml'), |
| 90 | + fallback: {} |
| 91 | + ).deep_symbolize_keys |
89 | 92 | expect(example_config).to eq(described_class.defaults) |
90 | 93 | end |
91 | 94 | end |
|
0 commit comments