cascading-configuration-hash 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,402 @@
1
+
2
+ require_relative '../../lib/cascading-configuration-hash.rb'
3
+
4
+ describe CascadingConfiguration::CascadingCompositeHash do
5
+
6
+ #########
7
+ # []= #
8
+ #########
9
+
10
+ it 'can add elements' do
11
+ # primary class
12
+ class CascadingConfiguration::CascadingCompositeHash::Mock01
13
+ include CascadingConfiguration::ConfigurationVariable
14
+ include CascadingConfiguration::CascadingCompositeHash::Instance
15
+ end
16
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock01
17
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
18
+ cascading_composite_hash[ :some_setting ] = :some_value
19
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
20
+ cascading_composite_hash.should == { :some_setting => :some_value }
21
+ cascading_composite_hash[ :other_setting ] = :some_value
22
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
23
+ :other_setting => :some_value }
24
+ cascading_composite_hash.should == { :some_setting => :some_value,
25
+ :other_setting => :some_value }
26
+ # instance
27
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock01.new
28
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
29
+ cascading_composite_hash.local_cascading_hash.should == {}
30
+ cascading_composite_hash.should == { :some_setting => :some_value,
31
+ :other_setting => :some_value }
32
+ cascading_composite_hash[ :another_setting ] = :some_value
33
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
34
+ cascading_composite_hash.should == { :some_setting => :some_value,
35
+ :other_setting => :some_value,
36
+ :another_setting => :some_value }
37
+ # inheriting class
38
+ class CascadingConfiguration::CascadingCompositeHash::Mock01sub1 < CascadingConfiguration::CascadingCompositeHash::Mock01
39
+ end
40
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock01sub1
41
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
42
+ cascading_composite_hash.local_cascading_hash.should == {}
43
+ cascading_composite_hash.should == { :some_setting => :some_value,
44
+ :other_setting => :some_value }
45
+ cascading_composite_hash[ :yet_another_setting ] = :some_value
46
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
47
+ cascading_composite_hash.should == { :some_setting => :some_value,
48
+ :other_setting => :some_value,
49
+ :yet_another_setting => :some_value }
50
+ # instance
51
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock01sub1.new
52
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
53
+ cascading_composite_hash.local_cascading_hash.should == {}
54
+ cascading_composite_hash.should == { :some_setting => :some_value,
55
+ :other_setting => :some_value,
56
+ :yet_another_setting => :some_value }
57
+ cascading_composite_hash[ :and_still_another_setting ] = :some_value
58
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
59
+ cascading_composite_hash.should == { :some_setting => :some_value,
60
+ :other_setting => :some_value,
61
+ :yet_another_setting => :some_value,
62
+ :and_still_another_setting => :some_value }
63
+ end
64
+
65
+ ###########
66
+ # store #
67
+ ###########
68
+
69
+ it 'can add elements' do
70
+ # primary class
71
+ class CascadingConfiguration::CascadingCompositeHash::Mock02
72
+ include CascadingConfiguration::ConfigurationVariable
73
+ include CascadingConfiguration::CascadingCompositeHash::Instance
74
+ end
75
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock02
76
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
77
+ cascading_composite_hash.store( :some_setting, :some_value )
78
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
79
+ cascading_composite_hash.should == { :some_setting => :some_value }
80
+ cascading_composite_hash.store( :other_setting, :some_value )
81
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
82
+ :other_setting => :some_value }
83
+ cascading_composite_hash.should == { :some_setting => :some_value,
84
+ :other_setting => :some_value }
85
+ # instance
86
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock02.new
87
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
88
+ cascading_composite_hash.local_cascading_hash.should == {}
89
+ cascading_composite_hash.should == { :some_setting => :some_value,
90
+ :other_setting => :some_value }
91
+ cascading_composite_hash.store( :another_setting, :some_value )
92
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
93
+ cascading_composite_hash.should == { :some_setting => :some_value,
94
+ :other_setting => :some_value,
95
+ :another_setting => :some_value }
96
+ # inheriting class
97
+ class CascadingConfiguration::CascadingCompositeHash::Mock02sub1 < CascadingConfiguration::CascadingCompositeHash::Mock02
98
+ end
99
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock02sub1
100
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
101
+ cascading_composite_hash.local_cascading_hash.should == {}
102
+ cascading_composite_hash.should == { :some_setting => :some_value,
103
+ :other_setting => :some_value }
104
+ cascading_composite_hash.store( :yet_another_setting, :some_value )
105
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
106
+ cascading_composite_hash.should == { :some_setting => :some_value,
107
+ :other_setting => :some_value,
108
+ :yet_another_setting => :some_value }
109
+ # instance
110
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock02sub1.new
111
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
112
+ cascading_composite_hash.local_cascading_hash.should == {}
113
+ cascading_composite_hash.should == { :some_setting => :some_value,
114
+ :other_setting => :some_value,
115
+ :yet_another_setting => :some_value }
116
+ cascading_composite_hash.store( :and_still_another_setting, :some_value )
117
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
118
+ cascading_composite_hash.should == { :some_setting => :some_value,
119
+ :other_setting => :some_value,
120
+ :yet_another_setting => :some_value,
121
+ :and_still_another_setting => :some_value }
122
+ end
123
+
124
+ ############
125
+ # delete #
126
+ ############
127
+
128
+ it 'can exclude elements' do
129
+ # primary class
130
+ class CascadingConfiguration::CascadingCompositeHash::Mock03
131
+ include CascadingConfiguration::ConfigurationVariable
132
+ include CascadingConfiguration::CascadingCompositeHash::Instance
133
+ end
134
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock03
135
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
136
+ cascading_composite_hash.store( :some_setting, :some_value )
137
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
138
+ cascading_composite_hash.should == { :some_setting => :some_value }
139
+ cascading_composite_hash.delete( :some_setting ).should == :some_value
140
+ cascading_composite_hash.should == {}
141
+ cascading_composite_hash.store( :other_setting, :some_value )
142
+ cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
143
+ cascading_composite_hash.should == { :other_setting => :some_value }
144
+ # instance
145
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock03.new
146
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
147
+ cascading_composite_hash.local_cascading_hash.should == {}
148
+ cascading_composite_hash.should == { :other_setting => :some_value }
149
+ cascading_composite_hash.delete( :other_setting ).should == :some_value
150
+ cascading_composite_hash.local_cascading_hash.should == {}
151
+ cascading_composite_hash.local_cascading_hash.exclude_array.should == [ :other_setting ]
152
+ cascading_composite_hash.should == {}
153
+ # inheriting class
154
+ class CascadingConfiguration::CascadingCompositeHash::Mock03sub1 < CascadingConfiguration::CascadingCompositeHash::Mock03
155
+ end
156
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock03sub1
157
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
158
+ cascading_composite_hash.local_cascading_hash.should == {}
159
+ cascading_composite_hash.should == { :other_setting => :some_value }
160
+ cascading_composite_hash.delete( :other_setting ).should == :some_value
161
+ cascading_composite_hash.local_cascading_hash.should == {}
162
+ cascading_composite_hash.local_cascading_hash.exclude_array.should == [ :other_setting ]
163
+ cascading_composite_hash.should == {}
164
+ # instance
165
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock03sub1.new
166
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
167
+ cascading_composite_hash.local_cascading_hash.should == {}
168
+ cascading_composite_hash.should == {}
169
+ cascading_composite_hash.store( :and_still_another_setting, :some_value )
170
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
171
+ cascading_composite_hash.should == { :and_still_another_setting => :some_value }
172
+ cascading_composite_hash.delete( :and_still_another_setting ).should == :some_value
173
+ cascading_composite_hash.should == {}
174
+ end
175
+
176
+ ############
177
+ # merge! #
178
+ ############
179
+
180
+ it 'can merge from another hash' do
181
+ # primary class
182
+ class CascadingConfiguration::CascadingCompositeHash::Mock04
183
+ include CascadingConfiguration::ConfigurationVariable
184
+ include CascadingConfiguration::CascadingCompositeHash::Instance
185
+ end
186
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock04
187
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
188
+ cascading_composite_hash.merge!( :some_setting => :some_value )
189
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
190
+ cascading_composite_hash.should == { :some_setting => :some_value }
191
+ cascading_composite_hash.merge!( :other_setting => :some_value )
192
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value,
193
+ :other_setting => :some_value }
194
+ cascading_composite_hash.should == { :some_setting => :some_value,
195
+ :other_setting => :some_value }
196
+ # instance
197
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock04.new
198
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
199
+ cascading_composite_hash.local_cascading_hash.should == {}
200
+ cascading_composite_hash.should == { :some_setting => :some_value,
201
+ :other_setting => :some_value }
202
+ cascading_composite_hash.merge!( :another_setting => :some_value )
203
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
204
+ cascading_composite_hash.should == { :some_setting => :some_value,
205
+ :other_setting => :some_value,
206
+ :another_setting => :some_value }
207
+ # inheriting class
208
+ class CascadingConfiguration::CascadingCompositeHash::Mock04sub1 < CascadingConfiguration::CascadingCompositeHash::Mock04
209
+ end
210
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock04sub1
211
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
212
+ cascading_composite_hash.local_cascading_hash.should == {}
213
+ cascading_composite_hash.should == { :some_setting => :some_value,
214
+ :other_setting => :some_value }
215
+ cascading_composite_hash.merge!( :yet_another_setting => :some_value )
216
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
217
+ cascading_composite_hash.should == { :some_setting => :some_value,
218
+ :other_setting => :some_value,
219
+ :yet_another_setting => :some_value }
220
+ # instance
221
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock04sub1.new
222
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
223
+ cascading_composite_hash.local_cascading_hash.should == {}
224
+ cascading_composite_hash.should == { :some_setting => :some_value,
225
+ :other_setting => :some_value,
226
+ :yet_another_setting => :some_value }
227
+ cascading_composite_hash.merge!( :and_still_another_setting => :some_value )
228
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
229
+ cascading_composite_hash.should == { :some_setting => :some_value,
230
+ :other_setting => :some_value,
231
+ :yet_another_setting => :some_value,
232
+ :and_still_another_setting => :some_value }
233
+ end
234
+
235
+ #############
236
+ # replace #
237
+ #############
238
+
239
+ it 'can replace existing elements with others' do
240
+ # primary class
241
+ class CascadingConfiguration::CascadingCompositeHash::Mock05
242
+ include CascadingConfiguration::ConfigurationVariable
243
+ include CascadingConfiguration::CascadingCompositeHash::Instance
244
+ end
245
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock05
246
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
247
+ cascading_composite_hash.replace( :some_setting => :some_value )
248
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
249
+ cascading_composite_hash.should == { :some_setting => :some_value }
250
+ cascading_composite_hash.replace( :other_setting => :some_value )
251
+ cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
252
+ cascading_composite_hash.should == { :other_setting => :some_value }
253
+ # instance
254
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock05.new
255
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
256
+ cascading_composite_hash.local_cascading_hash.should == {}
257
+ cascading_composite_hash.should == { :other_setting => :some_value }
258
+ cascading_composite_hash.replace( :another_setting => :some_value )
259
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
260
+ cascading_composite_hash.should == { :another_setting => :some_value }
261
+ # inheriting class
262
+ class CascadingConfiguration::CascadingCompositeHash::Mock05sub1 < CascadingConfiguration::CascadingCompositeHash::Mock05
263
+ end
264
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock05sub1
265
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
266
+ cascading_composite_hash.local_cascading_hash.should == {}
267
+ cascading_composite_hash.should == { :other_setting => :some_value }
268
+ cascading_composite_hash.replace( :yet_another_setting => :some_value )
269
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
270
+ cascading_composite_hash.should == { :yet_another_setting => :some_value }
271
+ # instance
272
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock05sub1.new
273
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
274
+ cascading_composite_hash.local_cascading_hash.should == {}
275
+ cascading_composite_hash.should == { :yet_another_setting => :some_value }
276
+ cascading_composite_hash.replace( :and_still_another_setting => :some_value )
277
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
278
+ cascading_composite_hash.should == { :and_still_another_setting => :some_value }
279
+ end
280
+
281
+ ###########
282
+ # shift #
283
+ ###########
284
+
285
+ it 'can shift the first element' do
286
+ # primary class
287
+ class CascadingConfiguration::CascadingCompositeHash::Mock06
288
+ include CascadingConfiguration::ConfigurationVariable
289
+ include CascadingConfiguration::CascadingCompositeHash::Instance
290
+ end
291
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock06
292
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
293
+ cascading_composite_hash.replace( :some_setting => :some_value )
294
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
295
+ cascading_composite_hash.should == { :some_setting => :some_value }
296
+ cascading_composite_hash.shift.should == [ :some_setting, :some_value ]
297
+ cascading_composite_hash.should == {}
298
+ cascading_composite_hash.replace( :other_setting => :some_value )
299
+ cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
300
+ cascading_composite_hash.should == { :other_setting => :some_value }
301
+ cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
302
+ cascading_composite_hash.should == {}
303
+ # instance
304
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock06.new
305
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
306
+ cascading_composite_hash.local_cascading_hash.should == {}
307
+ cascading_composite_hash.replace( :other_setting => :some_value )
308
+ cascading_composite_hash.should == { :other_setting => :some_value }
309
+ cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
310
+ cascading_composite_hash.should == {}
311
+ cascading_composite_hash.replace( :another_setting => :some_value )
312
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
313
+ cascading_composite_hash.should == { :another_setting => :some_value }
314
+ cascading_composite_hash.shift.should == [ :another_setting, :some_value ]
315
+ cascading_composite_hash.should == {}
316
+ # inheriting class
317
+ class CascadingConfiguration::CascadingCompositeHash::Mock06sub1 < CascadingConfiguration::CascadingCompositeHash::Mock06
318
+ end
319
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock06sub1
320
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
321
+ cascading_composite_hash.local_cascading_hash.should == {}
322
+ cascading_composite_hash.replace( :other_setting => :some_value )
323
+ cascading_composite_hash.should == { :other_setting => :some_value }
324
+ cascading_composite_hash.shift.should == [ :other_setting, :some_value ]
325
+ cascading_composite_hash.should == {}
326
+ cascading_composite_hash.replace( :yet_another_setting => :some_value )
327
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
328
+ cascading_composite_hash.should == { :yet_another_setting => :some_value }
329
+ cascading_composite_hash.shift.should == [ :yet_another_setting, :some_value ]
330
+ cascading_composite_hash.should == {}
331
+ # instance
332
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock06sub1.new
333
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
334
+ cascading_composite_hash.local_cascading_hash.should == {}
335
+ cascading_composite_hash.replace( :yet_another_setting => :some_value )
336
+ cascading_composite_hash.should == { :yet_another_setting => :some_value }
337
+ cascading_composite_hash.shift.should == [ :yet_another_setting, :some_value ]
338
+ cascading_composite_hash.should == {}
339
+ cascading_composite_hash.replace( :and_still_another_setting => :some_value )
340
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
341
+ cascading_composite_hash.should == { :and_still_another_setting => :some_value }
342
+ cascading_composite_hash.shift.should == [ :and_still_another_setting, :some_value ]
343
+ cascading_composite_hash.should == {}
344
+ end
345
+
346
+ ###########
347
+ # clear #
348
+ ###########
349
+
350
+ it 'can clear, causing present elements to be excluded' do
351
+ # primary class
352
+ class CascadingConfiguration::CascadingCompositeHash::Mock07
353
+ include CascadingConfiguration::ConfigurationVariable
354
+ include CascadingConfiguration::CascadingCompositeHash::Instance
355
+ end
356
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock07
357
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
358
+ cascading_composite_hash.replace( :some_setting => :some_value )
359
+ cascading_composite_hash.local_cascading_hash.should == { :some_setting => :some_value }
360
+ cascading_composite_hash.should == { :some_setting => :some_value }
361
+ cascading_composite_hash.clear
362
+ cascading_composite_hash.should == {}
363
+ cascading_composite_hash.replace( :other_setting => :some_value )
364
+ cascading_composite_hash.local_cascading_hash.should == { :other_setting => :some_value }
365
+ cascading_composite_hash.should == { :other_setting => :some_value }
366
+ cascading_composite_hash.clear
367
+ cascading_composite_hash.should == {}
368
+ # instance
369
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock07.new
370
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
371
+ cascading_composite_hash.local_cascading_hash.should == {}
372
+ cascading_composite_hash.should == {}
373
+ cascading_composite_hash.replace( :another_setting => :some_value )
374
+ cascading_composite_hash.local_cascading_hash.should == { :another_setting => :some_value }
375
+ cascading_composite_hash.should == { :another_setting => :some_value }
376
+ cascading_composite_hash.clear
377
+ cascading_composite_hash.should == {}
378
+ # inheriting class
379
+ class CascadingConfiguration::CascadingCompositeHash::Mock07sub1 < CascadingConfiguration::CascadingCompositeHash::Mock07
380
+ end
381
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock07sub1
382
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
383
+ cascading_composite_hash.local_cascading_hash.should == {}
384
+ cascading_composite_hash.should == {}
385
+ cascading_composite_hash.replace( :yet_another_setting => :some_value )
386
+ cascading_composite_hash.local_cascading_hash.should == { :yet_another_setting => :some_value }
387
+ cascading_composite_hash.should == { :yet_another_setting => :some_value }
388
+ cascading_composite_hash.clear
389
+ cascading_composite_hash.should == {}
390
+ # instance
391
+ working_instance = CascadingConfiguration::CascadingCompositeHash::Mock07sub1.new
392
+ cascading_composite_hash = working_instance.composite_hash_for_cascading_configuration( :some_configuration )
393
+ cascading_composite_hash.local_cascading_hash.should == {}
394
+ cascading_composite_hash.should == {}
395
+ cascading_composite_hash.replace( :and_still_another_setting => :some_value )
396
+ cascading_composite_hash.local_cascading_hash.should == { :and_still_another_setting => :some_value }
397
+ cascading_composite_hash.should == { :and_still_another_setting => :some_value }
398
+ cascading_composite_hash.clear
399
+ cascading_composite_hash.should == {}
400
+ end
401
+
402
+ end
@@ -0,0 +1,95 @@
1
+
2
+ require_relative '../../lib/cascading-configuration-hash.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationHash do
5
+
6
+ #########
7
+ # []= #
8
+ #########
9
+
10
+ it 'can add elements' do
11
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
12
+ hash_instance[ :some_setting ] = :some_value
13
+ hash_instance.should == { :some_setting => :some_value }
14
+ hash_instance.exclude_array.include?( :some_setting ).should == false
15
+ hash_instance[ :other_setting ] = :some_value
16
+ hash_instance.should == { :some_setting => :some_value,
17
+ :other_setting => :some_value }
18
+ hash_instance.exclude_array.include?( :other_setting ).should == false
19
+ end
20
+
21
+ ###########
22
+ # store #
23
+ ###########
24
+
25
+ it 'can add elements' do
26
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
27
+ hash_instance.store( :some_setting, :some_value )
28
+ hash_instance.should == { :some_setting => :some_value }
29
+ hash_instance.exclude_array.include?( :some_setting ).should == false
30
+ hash_instance.store( :other_setting, :some_value )
31
+ hash_instance.should == { :some_setting => :some_value,
32
+ :other_setting => :some_value }
33
+ hash_instance.exclude_array.include?( :other_setting ).should == false
34
+ end
35
+
36
+ ############
37
+ # delete #
38
+ ############
39
+
40
+ it 'can exclude elements' do
41
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
42
+ hash_instance[ :some_setting ] = :some_value
43
+ hash_instance.delete( :some_setting ).should == :some_value
44
+ hash_instance.should == {}
45
+ hash_instance.exclude_array.include?( :some_setting ).should == true
46
+ end
47
+
48
+ ############
49
+ # merge! #
50
+ ############
51
+
52
+ it 'can merge from another hash' do
53
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
54
+ hash_instance.merge!( { :some_setting => :some_value } )
55
+ hash_instance.should == { :some_setting => :some_value }
56
+ end
57
+
58
+ #############
59
+ # replace #
60
+ #############
61
+
62
+ it 'can replace existing elements with others' do
63
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
64
+ hash_instance.merge!( { :some_setting => :some_value } )
65
+ hash_instance.should == { :some_setting => :some_value }
66
+ hash_instance.replace( { :other_setting => :some_value } )
67
+ hash_instance.should == { :other_setting => :some_value }
68
+ hash_instance.exclude_array.include?( :other_setting ).should == false
69
+ hash_instance.exclude_array.include?( :some_setting ).should == true
70
+ end
71
+
72
+ ###########
73
+ # shift #
74
+ ###########
75
+
76
+ it 'can shift the first element' do
77
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
78
+ hash_instance.merge!( { :some_setting => :some_value } )
79
+ hash_instance.shift.should == [ :some_setting, :some_value ]
80
+ hash_instance.should == {}
81
+ end
82
+
83
+ ###########
84
+ # clear #
85
+ ###########
86
+
87
+ it 'can clear, causing present elements to be excluded' do
88
+ hash_instance = ::CascadingConfiguration::ConfigurationHash.new
89
+ hash_instance.merge!( { :some_setting => :some_value } )
90
+ hash_instance.clear
91
+ hash_instance.should == {}
92
+ hash_instance.exclude_array.include?( :some_setting ).should == true
93
+ end
94
+
95
+ end
@@ -0,0 +1,28 @@
1
+
2
+ require_relative '../../../lib/cascading-configuration-hash.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationSettingsHash::Accessors do
5
+
6
+ ######################################
7
+ # define_configuration_hash_setter #
8
+ # define_configuration_hash_getter #
9
+ ######################################
10
+
11
+ it 'can define a method to get and modify the configuration hash' do
12
+ class CascadingConfiguration::ConfigurationSettingsHash::Mock
13
+ include CascadingConfiguration::ConfigurationVariable
14
+ extend CascadingConfiguration::ConfigurationSettingsHash::Accessors
15
+ include CascadingConfiguration::ConfigurationSettingsHash::ObjectInstance
16
+ extend CascadingConfiguration::ConfigurationSettingsHash::ClassInstance
17
+ end
18
+ # setter
19
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.define_configuration_hash_setter( :some_configuration )
20
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.methods.include?( :some_configuration= ).should == true
21
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.instance_methods.include?( :some_configuration= ).should == true
22
+ # getter
23
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.define_configuration_hash_getter( :some_configuration )
24
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.methods.include?( :some_configuration ).should == true
25
+ CascadingConfiguration::ConfigurationSettingsHash::Mock.instance_methods.include?( :some_configuration ).should == true
26
+ end
27
+
28
+ end
@@ -0,0 +1,110 @@
1
+
2
+ require_relative '../../lib/cascading-configuration-hash.rb'
3
+
4
+ describe CascadingConfiguration::ConfigurationSettingsHash do
5
+
6
+ #############################
7
+ # attr_configuration_hash #
8
+ #############################
9
+
10
+ it 'can define a configuration hash, which is the primary interface' do
11
+
12
+ module CascadingConfiguration::ConfigurationSettingsHash::MockModule
13
+ include CascadingConfiguration::ConfigurationSettingsHash
14
+ attr_configuration_hash :configuration_setting
15
+ configuration_setting.should == {}
16
+ self.configuration_setting[ :a_configuration ] = :some_value
17
+ configuration_setting.should == { :a_configuration => :some_value }
18
+ end
19
+
20
+ module CascadingConfiguration::ConfigurationSettingsHash::MockModule2
21
+ include CascadingConfiguration::ConfigurationSettingsHash::MockModule
22
+ configuration_setting.should == { :a_configuration => :some_value }
23
+ configuration_setting[ :other_setting ] = :some_value
24
+ configuration_setting.should == { :a_configuration => :some_value,
25
+ :other_setting => :some_value }
26
+ configuration_setting.delete( :other_setting ).should == :some_value
27
+ configuration_setting.should == { :a_configuration => :some_value }
28
+ end
29
+
30
+ module CascadingConfiguration::ConfigurationSettingsHash::MockModule3
31
+ include CascadingConfiguration::ConfigurationSettingsHash::MockModule2
32
+ end
33
+
34
+ class CascadingConfiguration::ConfigurationSettingsHash::MockClass
35
+ include CascadingConfiguration::ConfigurationSettingsHash::MockModule3
36
+ configuration_setting.should == { :a_configuration => :some_value }
37
+ configuration_setting[ :other_setting ] = :some_value
38
+ configuration_setting.should == { :a_configuration => :some_value,
39
+ :other_setting => :some_value }
40
+ configuration_setting.delete( :other_setting ).should == :some_value
41
+ configuration_setting.should == { :a_configuration => :some_value }
42
+ end
43
+
44
+ object_instance_one = CascadingConfiguration::ConfigurationSettingsHash::MockClass.new
45
+ object_instance_one.configuration_setting.should == { :a_configuration => :some_value }
46
+ object_instance_one.configuration_setting[ :some_other_configuration ] = :some_value
47
+ object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
48
+ :some_other_configuration => :some_value }
49
+
50
+ class CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1 < CascadingConfiguration::ConfigurationSettingsHash::MockClass
51
+ configuration_setting.should == { :a_configuration => :some_value }
52
+ self.configuration_setting[ :another_configuration ] = :some_value
53
+ configuration_setting.should == { :a_configuration => :some_value,
54
+ :another_configuration => :some_value }
55
+ end
56
+
57
+ CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.new.configuration_setting.should == { :a_configuration => :some_value,
58
+ :another_configuration => :some_value }
59
+
60
+ object_instance_two = CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.new
61
+ object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
62
+ :another_configuration => :some_value }
63
+ object_instance_two.configuration_setting[ :some_other_configuration ] = :some_value
64
+ object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
65
+ :another_configuration => :some_value,
66
+ :some_other_configuration => :some_value }
67
+
68
+ # change ancestor setting
69
+ CascadingConfiguration::ConfigurationSettingsHash::MockClass.configuration_setting[ :a_yet_unused_configuration ] = :some_value
70
+ CascadingConfiguration::ConfigurationSettingsHash::MockClass.configuration_setting.should == { :a_configuration => :some_value,
71
+ :a_yet_unused_configuration => :some_value }
72
+ object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
73
+ :a_yet_unused_configuration => :some_value,
74
+ :some_other_configuration => :some_value }
75
+ CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
76
+ :a_yet_unused_configuration => :some_value,
77
+ :another_configuration => :some_value }
78
+ object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
79
+ :a_yet_unused_configuration => :some_value,
80
+ :another_configuration => :some_value,
81
+ :some_other_configuration => :some_value }
82
+
83
+ # freeze ancestor setting
84
+ object_instance_one.configuration_setting.freeze!
85
+ object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
86
+ :a_yet_unused_configuration => :some_value,
87
+ :some_other_configuration => :some_value }
88
+ CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.configuration_setting.freeze!
89
+ CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
90
+ :a_yet_unused_configuration => :some_value,
91
+ :another_configuration => :some_value }
92
+ CascadingConfiguration::ConfigurationSettingsHash::MockClass.configuration_setting[ :non_cascading_configuration ] = :some_value
93
+ CascadingConfiguration::ConfigurationSettingsHash::MockClass.configuration_setting.should == { :a_configuration => :some_value,
94
+ :a_yet_unused_configuration => :some_value,
95
+ :non_cascading_configuration => :some_value }
96
+ object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
97
+ :a_yet_unused_configuration => :some_value,
98
+ :some_other_configuration => :some_value }
99
+ CascadingConfiguration::ConfigurationSettingsHash::MockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
100
+ :a_yet_unused_configuration => :some_value,
101
+ :another_configuration => :some_value }
102
+ object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
103
+ :a_yet_unused_configuration => :some_value,
104
+ :another_configuration => :some_value,
105
+ :some_other_configuration => :some_value }
106
+
107
+
108
+ end
109
+
110
+ end