-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathhash_source_spec.rb
More file actions
99 lines (87 loc) · 2.89 KB
/
hash_source_spec.rb
File metadata and controls
99 lines (87 loc) · 2.89 KB
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
require 'spec_helper'
module Config::Sources
describe HashSource do
it "should take a hash as initializer" do
source = HashSource.new(foo: 5)
expect(source.hash).to eq(foo: 5)
end
context "basic hash" do
let(:source) do
example_hash =
{
"size" => 2,
"section" => {
"size" => 3,
"servers" => [ {"name" => "yahoo.com"}, {"name" => "amazon.com"} ]
}
}
HashSource.new(example_hash)
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 hash with single namespace" do
let(:source) do
example_hash =
{
"size" => 2,
"section" => {
"size" => 3,
"servers" => [ {"name" => "yahoo.com"}, {"name" => "amazon.com"} ]
}
}
HashSource.new(example_hash, '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 hash with nested namespace" do
let(:source) do
example_hash =
{
"size" => 2,
"section" => {
"size" => 3,
"servers" => [ {"name" => "yahoo.com"}, {"name" => "amazon.com"} ]
}
}
HashSource.new(example_hash, ['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 "parameter is not a hash" do
let(:source) do
HashSource.new "hello world"
end
it "should return an empty hash" do
results = source.load
expect(results).to eq({})
end
end
end
end