-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathyaml_source_spec.rb
113 lines (94 loc) · 3.28 KB
/
yaml_source_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'spec_helper'
module Config::Sources
describe YAMLSource do
it "should take a path as initializer" do
source = YAMLSource.new "somepath"
expect(source.path).to eq("somepath")
end
context "basic yml file" do
let(:source) do
YAMLSource.new "#{fixture_path}/development.yml"
end
it "should properly read the settings" do
results = source.load
expect(results["size"]).to eq(2)
end
it "should properly read nested settings" do
results = source.load
expect(results["section"]["size"]).to eq(3)
expect(results["section"]["servers"]).to be_instance_of(Array)
expect(results["section"]["servers"].size).to eq(2)
end
end
context "basic yml file with single namespace" do
let(:source) do
YAMLSource.new "#{fixture_path}/development.yml", 'test_namespace'
end
it "should properly read the settings" do
results = source.load
expect(results['test_namespace']["size"]).to eq(2)
end
it "should properly read nested settings" do
results = source.load
expect(results['test_namespace']["section"]["size"]).to eq(3)
expect(results['test_namespace']["section"]["servers"]).to be_instance_of(Array)
expect(results['test_namespace']["section"]["servers"].size).to eq(2)
end
end
context "basic yml file with nested namespace" do
let(:source) do
YAMLSource.new "#{fixture_path}/development.yml", ['test_namespace', 'test_layer_2']
end
it "should properly read the settings" do
results = source.load
expect(results['test_namespace']['test_layer_2']["size"]).to eq(2)
end
it "should properly read nested settings" do
results = source.load
expect(results['test_namespace']['test_layer_2']["section"]["size"]).to eq(3)
expect(results['test_namespace']['test_layer_2']["section"]["servers"]).to be_instance_of(Array)
expect(results['test_namespace']['test_layer_2']["section"]["servers"].size).to eq(2)
end
end
context "yml file with erb tags" do
let(:source) do
YAMLSource.new "#{fixture_path}/with_erb.yml"
end
it "should properly evaluate the erb" do
results = source.load
expect(results["computed"]).to eq(6)
end
it "should properly evaluate the nested erb settings" do
results = source.load
expect(results["section"]["computed1"]).to eq(1)
expect(results["section"]["computed2"]).to eq(2)
end
end
context "missing yml file" do
let(:source) do
YAMLSource.new "somewhere_that_doesnt_exist.yml"
end
it "should return an empty hash" do
results = source.load
expect(results).to eq({})
end
end
context "blank yml file" do
let(:source) do
YAMLSource.new "#{fixture_path}/empty1.yml"
end
it "should return an empty hash" do
results = source.load
expect(results).to eq({})
end
end
context "malformed yml file" do
let(:source) do
YAMLSource.new "#{fixture_path}/malformed.yml"
end
it "should raise an useful exception" do
expect { source.load }.to raise_error(/malformed\.yml/)
end
end
end
end