hiera 0.3.0 → 1.0.0rc4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hiera might be problematic. Click here for more details.

@@ -1,283 +1,337 @@
1
1
  require 'spec_helper'
2
+ require 'hiera/util'
2
3
 
3
4
  class Hiera
4
- describe Backend do
5
- describe "#datadir" do
6
- it "should use the backend configured dir" do
7
- Config.load({:rspec => {:datadir => "/tmp"}})
8
- Backend.expects(:parse_string).with("/tmp", {})
9
- Backend.datadir(:rspec, {})
10
- end
11
-
12
- it "should default to /var/lib/hiera" do
13
- Config.load({})
14
- Backend.expects(:parse_string).with("/var/lib/hiera", {})
15
- Backend.datadir(:rspec, {})
16
- end
17
- end
18
-
19
- describe "#empty_anwer" do
20
- it "should return [] for array searches" do
21
- Backend.empty_answer(:array).should == []
22
- end
23
-
24
- it "should return {} for hash searches" do
25
- Backend.empty_answer(:hash).should == {}
26
- end
5
+ describe Backend do
6
+ describe "#datadir" do
7
+ it "should use the backend configured dir" do
8
+ Config.load({:rspec => {:datadir => "/tmp"}})
9
+ Backend.expects(:parse_string).with("/tmp", {})
10
+ Backend.datadir(:rspec, {})
11
+ end
12
+
13
+ it "should use a default var directory" do
14
+ Config.load({})
15
+ Backend.expects(:parse_string).with(Hiera::Util.var_dir, {})
16
+ Backend.datadir(:rspec, {})
17
+ end
18
+ end
27
19
 
28
- it "should return nil otherwise" do
29
- Backend.empty_answer(:meh).should == nil
30
- end
31
- end
20
+ describe "#datafile" do
21
+ it "should check if the file exist and return nil if not" do
22
+ Hiera.expects(:debug).with("Cannot find datafile /nonexisting/test.yaml, skipping")
23
+ Backend.expects(:datadir).returns("/nonexisting")
24
+ Backend.datafile(:yaml, {}, "test", "yaml").should == nil
25
+ end
26
+
27
+ it "should return the correct file name" do
28
+ Backend.expects(:datadir).returns("/nonexisting")
29
+ File.expects(:exist?).with("/nonexisting/test.yaml").returns(true)
30
+ Backend.datafile(:yaml, {}, "test", "yaml").should == "/nonexisting/test.yaml"
31
+ end
32
+ end
32
33
 
33
- describe "#datafile" do
34
- it "should check if the file exist and return nil if not" do
35
- Hiera.expects(:debug).with("Cannot find datafile /nonexisting/test.yaml, skipping")
36
- Backend.expects(:datadir).returns("/nonexisting")
37
- Backend.datafile(:yaml, {}, "test", "yaml").should == nil
38
- end
39
-
40
- it "should return the correct file name" do
41
- Backend.expects(:datadir).returns("/nonexisting")
42
- File.expects(:exist?).with("/nonexisting/test.yaml").returns(true)
43
- Backend.datafile(:yaml, {}, "test", "yaml").should == "/nonexisting/test.yaml"
44
- end
34
+ describe "#datasources" do
35
+ it "should use the supplied hierarchy" do
36
+ expected = ["one", "two"]
37
+ Backend.datasources({}, nil, ["one", "two"]) do |backend|
38
+ backend.should == expected.delete_at(0)
45
39
  end
46
40
 
47
- describe "#datasources" do
48
- it "should use the supplied hierarchy" do
49
- expected = ["one", "two"]
50
- Backend.datasources({}, nil, ["one", "two"]) do |backend|
51
- backend.should == expected.delete_at(0)
52
- end
53
-
54
- expected.empty?.should == true
55
- end
56
-
57
- it "should use the configured hierarchy if none is supplied" do
58
- Config.load(:hierarchy => "test")
59
-
60
- Backend.datasources({}) do |backend|
61
- backend.should == "test"
62
- end
63
- end
41
+ expected.empty?.should == true
42
+ end
64
43
 
65
- it "should default to common if not configured or supplied" do
66
- Config.load({})
44
+ it "should use the configured hierarchy if none is supplied" do
45
+ Config.load(:hierarchy => "test")
67
46
 
68
- Backend.datasources({}) do |backend|
69
- backend.should == "common"
70
- end
71
- end
72
-
73
- it "should insert the override if provided" do
74
- Config.load({})
75
-
76
- expected = ["override", "common"]
77
- Backend.datasources({}, "override") do |backend|
78
- backend.should == expected.delete_at(0)
79
- end
80
-
81
- expected.empty?.should == true
82
- end
83
-
84
- it "should parse the sources based on scope" do
85
- Backend.expects(:parse_string).with("common", {:rspec => :tests})
86
- Backend.datasources({:rspec => :tests}) { }
87
- end
88
-
89
- it "should not return empty sources" do
90
- Config.load({})
91
-
92
- expected = ["common"]
93
- Backend.datasources({}, "%{rspec}") do |backend|
94
- backend.should == expected.delete_at(0)
95
- end
96
-
97
- expected.empty?.should == true
98
- end
47
+ Backend.datasources({}) do |backend|
48
+ backend.should == "test"
99
49
  end
50
+ end
100
51
 
101
- describe "#parse_string" do
102
- it "should not try to parse invalid data" do
103
- Backend.parse_string(nil, {}).should == nil
104
- end
105
-
106
- it "should clone the supplied data" do
107
- data = ""
108
- data.expects(:clone).returns("")
109
- Backend.parse_string(data, {})
110
- end
111
-
112
- it "should only parse string data" do
113
- data = ""
114
- data.expects(:is_a?).with(String)
115
- Backend.parse_string(data, {})
116
- end
117
-
118
- it "should match data from scope" do
119
- input = "test_%{rspec}_test"
120
- Backend.parse_string(input, {"rspec" => "test"}).should == "test_test_test"
121
- end
122
-
123
- it "should match data from extra_data" do
124
- input = "test_%{rspec}_test"
125
- Backend.parse_string(input, {}, {"rspec" => "test"}).should == "test_test_test"
126
- end
127
-
128
- it "should prefer scope over extra_data" do
129
- input = "test_%{rspec}_test"
130
- Backend.parse_string(input, {"rspec" => "test"}, {"rspec" => "fail"}).should == "test_test_test"
131
- end
132
-
133
- it "should treat :undefined in scope as empty" do
134
- input = "test_%{rspec}_test"
135
- Backend.parse_string(input, {"rspec" => :undefined}).should == "test__test"
136
- end
137
- end
52
+ it "should default to common if not configured or supplied" do
53
+ Config.load({})
138
54
 
139
- describe "#parse_answer" do
140
- it "should parse strings correctly" do
141
- input = "test_%{rspec}_test"
142
- Backend.parse_answer(input, {"rspec" => "test"}).should == "test_test_test"
143
- end
144
-
145
- it "should parse each string in an array" do
146
- input = ["test_%{rspec}_test", "test_%{rspec}_test", ["test_%{rspec}_test"]]
147
- Backend.parse_answer(input, {"rspec" => "test"}).should == ["test_test_test", "test_test_test", ["test_test_test"]]
148
- end
149
-
150
- it "should parse each string in a hash" do
151
- input = {"foo" => "test_%{rspec}_test", "bar" => "test_%{rspec}_test"}
152
- Backend.parse_answer(input, {"rspec" => "test"}).should == {"foo"=>"test_test_test", "bar"=>"test_test_test"}
153
- end
154
-
155
- it "should parse mixed arrays and hashes" do
156
- input = {"foo" => "test_%{rspec}_test", "bar" => ["test_%{rspec}_test", "test_%{rspec}_test"]}
157
- Backend.parse_answer(input, {"rspec" => "test"}).should == {"foo"=>"test_test_test", "bar"=>["test_test_test", "test_test_test"]}
158
- end
159
-
160
- it "should parse integers correctly" do
161
- input = 1
162
- Backend.parse_answer(input, {"rspec" => "test"}).should == 1
163
- end
164
-
165
- it "should parse floats correctly" do
166
- input = 0.233
167
- Backend.parse_answer(input, {"rspec" => "test"}).should == 0.233
168
- end
169
-
170
- it "should parse true boolean values correctly" do
171
- input = true
172
- Backend.parse_answer(input, {"rspec" => "test"}).should == true
173
- end
174
-
175
- it "should parse false boolean values correctly" do
176
- input = false
177
- Backend.parse_answer(input, {"rspec" => "test"}).should == false
178
- end
55
+ Backend.datasources({}) do |backend|
56
+ backend.should == "common"
179
57
  end
58
+ end
180
59
 
181
- describe "#resolve_answer" do
182
- it "should correctly parse array data" do
183
- Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :array).should == ["foo", "bar"]
184
- end
60
+ it "should insert the override if provided" do
61
+ Config.load({})
185
62
 
186
- it "should just return the answer for non array data" do
187
- Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :priority).should == ["foo", ["foo", "foo"], "bar"]
188
- end
63
+ expected = ["override", "common"]
64
+ Backend.datasources({}, "override") do |backend|
65
+ backend.should == expected.delete_at(0)
189
66
  end
190
67
 
191
- describe "#lookup" do
192
- before do
193
- Hiera.stubs(:debug)
194
- Hiera.stubs(:warn)
195
- end
196
-
197
- it "should cache backends" do
198
- Hiera.expects(:debug).with(regexp_matches(/Hiera YAML backend starting/)).once
68
+ expected.empty?.should == true
69
+ end
199
70
 
200
- Config.load({:yaml => {:datadir => "/tmp"}})
201
- Config.load_backends
71
+ it "should parse the sources based on scope" do
72
+ Backend.expects(:parse_string).with("common", {:rspec => :tests})
73
+ Backend.datasources({:rspec => :tests}) { }
74
+ end
202
75
 
203
- Backend.lookup("key", "default", {}, nil, nil)
204
- Backend.lookup("key", "default", {}, nil, nil)
205
- end
76
+ it "should not return empty sources" do
77
+ Config.load({})
206
78
 
207
- it "should return the answer from the backend" do
208
- Config.load({:yaml => {:datadir => "/tmp"}})
209
- Config.load_backends
210
-
211
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil).returns("answer")
212
-
213
- Backend.lookup("key", "default", {}, nil, nil).should == "answer"
214
- end
215
-
216
- it "should retain the datatypes as returned by the backend" do
217
- Config.load({:yaml => {:datadir => "/tmp"}})
218
- Config.load_backends
219
-
220
- Backend::Yaml_backend.any_instance.expects(:lookup).with("stringval", {}, nil, nil).returns("string")
221
- Backend::Yaml_backend.any_instance.expects(:lookup).with("boolval", {}, nil, nil).returns(false)
222
- Backend::Yaml_backend.any_instance.expects(:lookup).with("numericval", {}, nil, nil).returns(1)
223
-
224
- Backend.lookup("stringval", "default", {}, nil, nil).should == "string"
225
- Backend.lookup("boolval", "default", {}, nil, nil).should == false
226
- Backend.lookup("numericval", "default", {}, nil, nil).should == 1
227
- end
228
-
229
- it "should call to all backends till an answer is found" do
230
- backend = mock
231
- backend.expects(:lookup).returns("answer")
232
- Config.load({})
233
- Config.instance_variable_set("@config", {:backends => ["yaml", "rspec"]})
234
- Backend.instance_variable_set("@backends", {"rspec" => backend})
235
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil)
236
- Backend.expects(:constants).returns(["Yaml_backend", "Rspec_backend"]).twice
237
-
238
- Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "answer"
239
-
240
- end
241
-
242
- it "should parse the answers based on resolution_type" do
243
- Config.load({:yaml => {:datadir => "/tmp"}})
244
- Config.load_backends
245
-
246
- Backend.expects(:resolve_answer).with("test_test", :priority).returns("parsed")
247
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, :priority).returns("test_test")
248
-
249
- Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, :priority).should == "parsed"
250
- end
79
+ expected = ["common"]
80
+ Backend.datasources({}, "%{rspec}") do |backend|
81
+ backend.should == expected.delete_at(0)
82
+ end
251
83
 
252
- it "should return the default with variables parsed if nothing is found" do
253
- Config.load({:yaml => {:datadir => "/tmp"}})
254
- Config.load_backends
84
+ expected.empty?.should == true
85
+ end
86
+ end
255
87
 
256
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil)
88
+ describe "#parse_string" do
89
+ it "should not try to parse invalid data" do
90
+ Backend.parse_string(nil, {}).should == nil
91
+ end
92
+
93
+ it "should clone the supplied data" do
94
+ data = ""
95
+ data.expects(:clone).returns("")
96
+ Backend.parse_string(data, {})
97
+ end
98
+
99
+ it "should only parse string data" do
100
+ data = ""
101
+ data.expects(:is_a?).with(String)
102
+ Backend.parse_string(data, {})
103
+ end
104
+
105
+ it "should match data from scope" do
106
+ input = "test_%{rspec}_test"
107
+ Backend.parse_string(input, {"rspec" => "test"}).should == "test_test_test"
108
+ end
109
+
110
+ it "should match data from extra_data" do
111
+ input = "test_%{rspec}_test"
112
+ Backend.parse_string(input, {}, {"rspec" => "test"}).should == "test_test_test"
113
+ end
114
+
115
+ it "should prefer scope over extra_data" do
116
+ input = "test_%{rspec}_test"
117
+ Backend.parse_string(input, {"rspec" => "test"}, {"rspec" => "fail"}).should == "test_test_test"
118
+ end
119
+
120
+ it "should treat :undefined in scope as empty" do
121
+ input = "test_%{rspec}_test"
122
+ Backend.parse_string(input, {"rspec" => :undefined}).should == "test__test"
123
+ end
124
+
125
+ it "should match data from extra_data when scope contains :undefined" do
126
+ input = "test_%{rspec}_test"
127
+ Backend.parse_string(input, {"rspec" => :undefined}, {"rspec" => "test"}).should == "test_test_test"
128
+ end
129
+
130
+ it "should match data in puppet ${::fact} style" do
131
+ input = "test_%{::rspec}_test"
132
+ Backend.parse_string(input, {"rspec" => "test"}).should == "test_test_test"
133
+ end
134
+ end
257
135
 
258
- Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "test_test"
259
- end
136
+ describe "#parse_answer" do
137
+ it "should parse strings correctly" do
138
+ input = "test_%{rspec}_test"
139
+ Backend.parse_answer(input, {"rspec" => "test"}).should == "test_test_test"
140
+ end
141
+
142
+ it "should parse each string in an array" do
143
+ input = ["test_%{rspec}_test", "test_%{rspec}_test", ["test_%{rspec}_test"]]
144
+ Backend.parse_answer(input, {"rspec" => "test"}).should == ["test_test_test", "test_test_test", ["test_test_test"]]
145
+ end
146
+
147
+ it "should parse each string in a hash" do
148
+ input = {"foo" => "test_%{rspec}_test", "bar" => "test_%{rspec}_test"}
149
+ Backend.parse_answer(input, {"rspec" => "test"}).should == {"foo"=>"test_test_test", "bar"=>"test_test_test"}
150
+ end
151
+
152
+ it "should parse mixed arrays and hashes" do
153
+ input = {"foo" => "test_%{rspec}_test", "bar" => ["test_%{rspec}_test", "test_%{rspec}_test"]}
154
+ Backend.parse_answer(input, {"rspec" => "test"}).should == {"foo"=>"test_test_test", "bar"=>["test_test_test", "test_test_test"]}
155
+ end
156
+
157
+ it "should parse integers correctly" do
158
+ input = 1
159
+ Backend.parse_answer(input, {"rspec" => "test"}).should == 1
160
+ end
161
+
162
+ it "should parse floats correctly" do
163
+ input = 0.233
164
+ Backend.parse_answer(input, {"rspec" => "test"}).should == 0.233
165
+ end
166
+
167
+ it "should parse true boolean values correctly" do
168
+ input = true
169
+ Backend.parse_answer(input, {"rspec" => "test"}).should == true
170
+ end
171
+
172
+ it "should parse false boolean values correctly" do
173
+ input = false
174
+ Backend.parse_answer(input, {"rspec" => "test"}).should == false
175
+ end
176
+ end
260
177
 
261
- it "should correctly handle string default data" do
262
- Config.load({:yaml => {:datadir => "/tmp"}})
263
- Config.load_backends
264
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil)
265
- Backend.lookup("key", "test", {}, nil, nil).should == "test"
266
- end
178
+ describe "#resolve_answer" do
179
+ it "should correctly parse array data" do
180
+ Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :array).should == ["foo", "bar"]
181
+ end
267
182
 
268
- it "should correctly handle array default data" do
269
- Config.load({:yaml => {:datadir => "/tmp"}})
270
- Config.load_backends
271
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array)
272
- Backend.lookup("key", ["test"], {}, nil, :array).should == ["test"]
273
- end
183
+ it "should just return the answer for non array data" do
184
+ Backend.resolve_answer(["foo", ["foo", "foo"], "bar"], :priority).should == ["foo", ["foo", "foo"], "bar"]
185
+ end
186
+ end
274
187
 
275
- it "should correctly handle hash default data" do
276
- Config.load({:yaml => {:datadir => "/tmp"}})
277
- Config.load_backends
278
- Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :hash)
279
- Backend.lookup("key", {"test" => "value"}, {}, nil, :hash).should == {"test" => "value"}
280
- end
281
- end
188
+ describe "#lookup" do
189
+ before do
190
+ Hiera.stubs(:debug)
191
+ Hiera.stubs(:warn)
192
+ end
193
+
194
+ it "should cache backends" do
195
+ Hiera.expects(:debug).with(regexp_matches(/Hiera YAML backend starting/)).once
196
+
197
+ Config.load({:yaml => {:datadir => "/tmp"}})
198
+ Config.load_backends
199
+
200
+ Backend.lookup("key", "default", {}, nil, nil)
201
+ Backend.lookup("key", "default", {}, nil, nil)
202
+ end
203
+
204
+ it "should return the answer from the backend" do
205
+ Config.load({:yaml => {:datadir => "/tmp"}})
206
+ Config.load_backends
207
+
208
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil).returns("answer")
209
+
210
+ Backend.lookup("key", "default", {}, nil, nil).should == "answer"
211
+ end
212
+
213
+ it "should retain the datatypes as returned by the backend" do
214
+ Config.load({:yaml => {:datadir => "/tmp"}})
215
+ Config.load_backends
216
+
217
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("stringval", {}, nil, nil).returns("string")
218
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("boolval", {}, nil, nil).returns(false)
219
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("numericval", {}, nil, nil).returns(1)
220
+
221
+ Backend.lookup("stringval", "default", {}, nil, nil).should == "string"
222
+ Backend.lookup("boolval", "default", {}, nil, nil).should == false
223
+ Backend.lookup("numericval", "default", {}, nil, nil).should == 1
224
+ end
225
+
226
+ it "should call to all backends till an answer is found" do
227
+ backend = mock
228
+ backend.expects(:lookup).returns("answer")
229
+ Config.load({})
230
+ Config.instance_variable_set("@config", {:backends => ["yaml", "rspec"]})
231
+ Backend.instance_variable_set("@backends", {"rspec" => backend})
232
+ #Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil)
233
+ Backend.expects(:constants).returns(["Yaml_backend", "Rspec_backend"]).twice
234
+
235
+ Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "answer"
236
+ end
237
+
238
+ it "should call to all backends till an answer is found when doing array lookups" do
239
+ backend = mock
240
+ backend.expects(:lookup).returns(["answer"])
241
+ Config.load({})
242
+ Config.instance_variable_set("@config", {:backends => ["yaml", "rspec"]})
243
+ Backend.instance_variable_set("@backends", {"rspec" => backend})
244
+ Backend.expects(:constants).returns(["Yaml_backend", "Rspec_backend"]).twice
245
+
246
+ Backend.lookup("key", "notfound", {"rspec" => "test"}, nil, :array).should == ["answer"]
247
+ end
248
+
249
+ it "should call to all backends till an answer is found when doing hash lookups" do
250
+ thehash = {:answer => "value"}
251
+ backend = mock
252
+ backend.expects(:lookup).returns(thehash)
253
+ Config.load({})
254
+ Config.instance_variable_set("@config", {:backends => ["yaml", "rspec"]})
255
+ Backend.instance_variable_set("@backends", {"rspec" => backend})
256
+ Backend.expects(:constants).returns(["Yaml_backend", "Rspec_backend"]).twice
257
+
258
+ Backend.lookup("key", "notfound", {"rspec" => "test"}, nil, :hash).should == thehash
259
+ end
260
+
261
+ it "should build a merged hash from all backends for hash searches" do
262
+ backend1 = mock :lookup => {"a" => "answer"}
263
+ backend2 = mock :lookup => {"b" => "bnswer"}
264
+ Config.load({})
265
+ Config.instance_variable_set("@config", {:backends => ["first", "second"]})
266
+ Backend.instance_variable_set("@backends", {"first" => backend1, "second" => backend2})
267
+ Backend.stubs(:constants).returns(["First_backend", "Second_backend"])
268
+
269
+ Backend.lookup("key", {}, {"rspec" => "test"}, nil, :hash).should == {"a" => "answer", "b" => "bnswer"}
270
+ end
271
+
272
+ it "should build an array from all backends for array searches" do
273
+ backend1 = mock :lookup => ["a", "b"]
274
+ backend2 = mock :lookup => ["c", "d"]
275
+ Config.load({})
276
+ Config.instance_variable_set("@config", {:backends => ["first", "second"]})
277
+ Backend.instance_variable_set("@backends", {"first" => backend1, "second" => backend2})
278
+ Backend.stubs(:constants).returns(["First_backend", "Second_backend"])
279
+
280
+ Backend.lookup("key", {}, {"rspec" => "test"}, nil, :array).should == ["a", "b", "c", "d"]
281
+ end
282
+
283
+ it "should use the earliest backend result for priority searches" do
284
+ backend1 = mock
285
+ backend1.stubs(:lookup).returns(["a", "b"])
286
+ backend2 = mock
287
+ backend2.stubs(:lookup).returns(["c", "d"])
288
+ Config.load({})
289
+ Config.instance_variable_set("@config", {:backends => ["first", "second"]})
290
+ Backend.instance_variable_set("@backends", {"first" => backend1, "second" => backend2})
291
+ Backend.stubs(:constants).returns(["First_backend", "Second_backend"])
292
+
293
+ Backend.lookup("key", {}, {"rspec" => "test"}, nil, :priority).should == ["a", "b"]
294
+ end
295
+
296
+ it "should parse the answers based on resolution_type" do
297
+ Config.load({:yaml => {:datadir => "/tmp"}})
298
+ Config.load_backends
299
+
300
+ Backend.expects(:resolve_answer).with("test_test", :priority).returns("parsed")
301
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, :priority).returns("test_test")
302
+
303
+ Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, :priority).should == "parsed"
304
+ end
305
+
306
+ it "should return the default with variables parsed if nothing is found" do
307
+ Config.load({:yaml => {:datadir => "/tmp"}})
308
+ Config.load_backends
309
+
310
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {"rspec" => "test"}, nil, nil)
311
+
312
+ Backend.lookup("key", "test_%{rspec}", {"rspec" => "test"}, nil, nil).should == "test_test"
313
+ end
314
+
315
+ it "should correctly handle string default data" do
316
+ Config.load({:yaml => {:datadir => "/tmp"}})
317
+ Config.load_backends
318
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, nil)
319
+ Backend.lookup("key", "test", {}, nil, nil).should == "test"
320
+ end
321
+
322
+ it "should correctly handle array default data" do
323
+ Config.load({:yaml => {:datadir => "/tmp"}})
324
+ Config.load_backends
325
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :array)
326
+ Backend.lookup("key", ["test"], {}, nil, :array).should == ["test"]
327
+ end
328
+
329
+ it "should correctly handle hash default data" do
330
+ Config.load({:yaml => {:datadir => "/tmp"}})
331
+ Config.load_backends
332
+ Backend::Yaml_backend.any_instance.expects(:lookup).with("key", {}, nil, :hash)
333
+ Backend.lookup("key", {"test" => "value"}, {}, nil, :hash).should == {"test" => "value"}
334
+ end
282
335
  end
336
+ end
283
337
  end