@@ -37,38 +37,16 @@ def read_file(path, expected_type, &block)
37
37
end
38
38
39
39
describe "#lookup" do
40
- it "should look for data in all sources" do
41
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
42
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( nil )
43
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( nil )
44
-
45
- @backend . lookup ( "key" , { } , nil , :priority )
46
- end
47
-
48
40
it "should pick data earliest source that has it for priority searches" do
49
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
50
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
51
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( nil ) . never
52
-
53
- @backend . stubs ( :file_exists? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
41
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . yields ( [ "one" , "/nonexisting/one.yaml" ] )
54
42
@cache . value = "---\n key: answer"
55
43
56
44
@backend . lookup ( "key" , { } , nil , :priority ) . should == "answer"
57
45
end
58
46
59
- it "should not look up missing data files" do
60
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] )
61
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( nil )
62
- YAML . expects ( :load_file ) . never
63
-
64
- @backend . lookup ( "key" , { } , nil , :priority )
65
- end
66
-
67
47
describe "handling unexpected YAML values" do
68
48
before do
69
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] )
70
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
71
- @backend . stubs ( :file_exists? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
49
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . yields ( [ "one" , "/nonexisting/one.yaml" ] )
72
50
end
73
51
74
52
it "returns nil when the YAML value is nil" do
@@ -88,24 +66,15 @@ def read_file(path, expected_type, &block)
88
66
end
89
67
90
68
it "should build an array of all data sources for array searches" do
91
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
92
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
93
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( "/nonexisting/two.yaml" )
94
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
95
- File . stubs ( :exist? ) . with ( "/nonexisting/two.yaml" ) . returns ( true )
96
-
69
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] , [ "two" , "/nonexisting/two.yaml" ] )
97
70
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { "key" => "answer" } )
98
71
@cache . expects ( :read_file ) . with ( "/nonexisting/two.yaml" , Hash ) . returns ( { "key" => "answer" } )
99
72
100
73
@backend . lookup ( "key" , { } , nil , :array ) . should == [ "answer" , "answer" ]
101
74
end
102
75
103
76
it "should ignore empty hash of data sources for hash searches" do
104
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
105
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
106
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( "/nonexisting/two.yaml" )
107
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
108
- File . stubs ( :exist? ) . with ( "/nonexisting/two.yaml" ) . returns ( true )
77
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] , [ "two" , "/nonexisting/two.yaml" ] )
109
78
110
79
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { } )
111
80
@cache . expects ( :read_file ) . with ( "/nonexisting/two.yaml" , Hash ) . returns ( { "key" => { "a" => "answer" } } )
@@ -114,11 +83,7 @@ def read_file(path, expected_type, &block)
114
83
end
115
84
116
85
it "should build a merged hash of data sources for hash searches" do
117
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
118
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
119
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( "/nonexisting/two.yaml" )
120
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
121
- File . stubs ( :exist? ) . with ( "/nonexisting/two.yaml" ) . returns ( true )
86
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] , [ "two" , "/nonexisting/two.yaml" ] )
122
87
123
88
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { "key" => { "a" => "answer" } } )
124
89
@cache . expects ( :read_file ) . with ( "/nonexisting/two.yaml" , Hash ) . returns ( { "key" => { "b" => "answer" , "a" => "wrong" } } )
@@ -127,11 +92,7 @@ def read_file(path, expected_type, &block)
127
92
end
128
93
129
94
it "should fail when trying to << a Hash" do
130
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
131
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
132
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( "/nonexisting/two.yaml" )
133
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
134
- File . stubs ( :exist? ) . with ( "/nonexisting/two.yaml" ) . returns ( true )
95
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] , [ "two" , "/nonexisting/two.yaml" ] )
135
96
136
97
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { "key" => [ "a" , "answer" ] } )
137
98
@cache . expects ( :read_file ) . with ( "/nonexisting/two.yaml" , Hash ) . returns ( { "key" => { "a" => "answer" } } )
@@ -140,11 +101,7 @@ def read_file(path, expected_type, &block)
140
101
end
141
102
142
103
it "should fail when trying to merge an Array" do
143
- Backend . expects ( :datasources ) . multiple_yields ( [ "one" ] , [ "two" ] )
144
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
145
- Backend . expects ( :datafile ) . with ( :yaml , { } , "two" , "yaml" ) . returns ( "/nonexisting/two.yaml" )
146
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
147
- File . stubs ( :exist? ) . with ( "/nonexisting/two.yaml" ) . returns ( true )
104
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] , [ "two" , "/nonexisting/two.yaml" ] )
148
105
149
106
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { "key" => { "a" => "answer" } } )
150
107
@cache . expects ( :read_file ) . with ( "/nonexisting/two.yaml" , Hash ) . returns ( { "key" => [ "a" , "wrong" ] } )
@@ -153,19 +110,15 @@ def read_file(path, expected_type, &block)
153
110
end
154
111
155
112
it "should parse the answer for scope variables" do
156
- Backend . expects ( :datasources ) . yields ( "one" )
157
- Backend . expects ( :datafile ) . with ( :yaml , { "rspec" => "test" } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" )
158
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
113
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { "rspec" => "test" } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] )
159
114
160
115
@cache . expects ( :read_file ) . with ( "/nonexisting/one.yaml" , Hash ) . returns ( { "key" => "test_%{rspec}" } )
161
116
162
117
@backend . lookup ( "key" , { "rspec" => "test" } , nil , :priority ) . should == "test_test"
163
118
end
164
119
165
120
it "should retain datatypes found in yaml files" do
166
- Backend . expects ( :datasources ) . yields ( "one" ) . times ( 3 )
167
- Backend . expects ( :datafile ) . with ( :yaml , { } , "one" , "yaml" ) . returns ( "/nonexisting/one.yaml" ) . times ( 3 )
168
- File . stubs ( :exist? ) . with ( "/nonexisting/one.yaml" ) . returns ( true )
121
+ Backend . expects ( :datasourcefiles ) . with ( :yaml , { } , "yaml" , nil ) . multiple_yields ( [ "one" , "/nonexisting/one.yaml" ] ) . times ( 3 )
169
122
170
123
171
124
@cache . value = "---\n stringval: 'string'\n boolval: true\n numericval: 1"
0 commit comments