configatron 2.9.1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Configatron::Rails do
4
+
5
+ %w{development test production cucumber}.each do |env|
6
+
7
+ describe env do
8
+
9
+ before(:each) do
10
+ Object.send(:remove_const, 'Rails') rescue nil
11
+ load File.expand_path(File.join(File.dirname(__FILE__), '..', 'support', 'rails.rb'))
12
+ ::Rails.env = env
13
+ ::Rails.root = File.join(File.dirname(__FILE__), '..', "tmp_rails_root_#{env}")
14
+ @configatron_path = File.join(Rails.root, 'config', 'configatron')
15
+ @defaults_file_loc = File.join(@configatron_path, 'defaults.rb')
16
+ @env_file_loc = File.join(@configatron_path, "#{env}.rb")
17
+ @env_folder_loc = File.join(@configatron_path, env)
18
+ @env_bar_loc = File.join(@env_folder_loc, 'bar.rb')
19
+ @env_foo_loc = File.join(@env_folder_loc, 'foo.rb')
20
+
21
+ FileUtils.mkdir_p(@env_folder_loc)
22
+
23
+ File.open(@defaults_file_loc, 'w') do |f|
24
+ f.puts 'configatron.fooa = :foo'
25
+ f.puts 'configatron.bara = :bar'
26
+ f.puts 'configatron.env = :default'
27
+ f.puts 'configatron.something.else = 1'
28
+ f.puts 'configatron.and.another.thing = 42'
29
+ end
30
+
31
+ File.open(@env_file_loc, 'w') do |f|
32
+ f.puts "configatron.env = :#{env}"
33
+ f.puts 'configatron.something.else = 2'
34
+ end
35
+
36
+ File.open(@env_bar_loc, 'w') do |f|
37
+ f.puts "configatron.bara = 'BAR!!'"
38
+ f.puts 'configatron.something.else = 3'
39
+ end
40
+
41
+ File.open(@env_foo_loc, 'w') do |f|
42
+ f.puts "configatron.fooa = :fubar"
43
+ f.puts 'configatron.something.else = 4'
44
+ end
45
+ end
46
+
47
+ after(:each) do
48
+ FileUtils.rm_rf(::Rails.root)
49
+ Object.send(:remove_const, 'Rails')
50
+ # configatron.reset!
51
+ end
52
+
53
+ it 'should read the defaults first and then the env file' do
54
+ Configatron::Rails.init
55
+ configatron.fooa.should == :fubar
56
+ configatron.bara.should == 'BAR!!'
57
+ configatron.env.should == env.to_sym
58
+ configatron.something.else.should == 4
59
+ configatron.and.another.thing.should == 42
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ configatron.foo.bar = :bar
4
+ configatron.a.b.c.d = 'D'
5
+
6
+ configatron.cachetastic.foo.bar = 'cachetastic-fubar'
7
+ configatron.l.m.n.o.p = 'P'
8
+
9
+ class Foo
10
+ end
11
+
12
+ module A
13
+ module B
14
+ class C
15
+ end
16
+ end
17
+ end
18
+
19
+ module N
20
+ class O
21
+ end
22
+ end
23
+
24
+ describe Class do
25
+
26
+ describe 'to_configatron' do
27
+
28
+ it 'should return a Configatron::Store object based on the name of the class' do
29
+ Foo.to_configatron.should be_kind_of(Configatron::Store)
30
+ Foo.to_configatron.bar.should == :bar
31
+ A::B::C.to_configatron.d.should == 'D'
32
+ end
33
+
34
+ it 'should take an array to prepend to the object' do
35
+ Foo.to_configatron(:cachetastic).bar.should == 'cachetastic-fubar'
36
+ N::O.to_configatron(:l, 'm').p.should == 'P'
37
+ end
38
+
39
+ it 'should convert a string to a Store object' do
40
+ 'A::B::C'.to_configatron.d.should == configatron.a.b.c.d
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,13 @@
1
+ complex_default: &default
2
+ access_key_id: access_key
3
+ secret_access_key: secret_access_key
4
+
5
+ complex_development:
6
+ bucket: develop
7
+ <<: *default
8
+
9
+ complex_production:
10
+ bucket: production
11
+ <<: *default
12
+
13
+ complex_test: &test
@@ -0,0 +1,613 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe "configatron" do
4
+
5
+ before(:each) do
6
+ configatron.reset!
7
+ end
8
+
9
+ it 'should respond to test without blowing up' do
10
+ configatron.test.should be_nil
11
+ configatron.test = 'hi!'
12
+ configatron.test.should == 'hi!'
13
+ configatron.foo.test.should be_nil
14
+ configatron.foo.test = 'hi!'
15
+ configatron.foo.test.should == 'hi!'
16
+ end
17
+
18
+ describe "respond_to" do
19
+
20
+ it 'should respond_to respond_to?' do
21
+ configatron.test.should be_nil
22
+ configatron.test = 'hi!'
23
+ configatron.respond_to?(:test).should be_true
24
+ configatron.respond_to?(:plop).should be_false
25
+ end
26
+
27
+ it 'should respond_to respond_to? recursively' do
28
+ configatron.foo.test.should be_nil
29
+ configatron.foo.test = 'hi!l'
30
+ configatron.foo.respond_to?(:test).should be_true
31
+ configatron.foo.respond_to?(:plop).should be_false
32
+ end
33
+
34
+ end
35
+
36
+ describe 'block assignment' do
37
+
38
+ it 'should pass the store to the block' do
39
+ configatron.test do |c|
40
+ c.should === configatron.test
41
+ end
42
+ end
43
+
44
+ it 'should persist changes outside of the block' do
45
+ configatron.test.one = 1
46
+ configatron.test.two = 2
47
+ configatron.test do |c|
48
+ c.two = 'two'
49
+ end
50
+ configatron.test.one.should === 1
51
+ configatron.test.two.should === 'two'
52
+ end
53
+
54
+ it 'should pass the default store to a temp block' do
55
+ configatron.temp do |c|
56
+ c.class.should == Configatron::Store
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ describe 'exists?' do
63
+
64
+ it 'should return true or false depending on whether or the setting exists' do
65
+ configatron.temp do
66
+ configatron.i.am.alive = 'alive!'
67
+ configatron.i.am.should be_exists(:alive)
68
+ configatron.i.am.should be_exists('alive')
69
+ end
70
+ configatron.i.am.should_not be_exists(:alive)
71
+ configatron.i.am.should_not be_exists('alive')
72
+ end
73
+
74
+ end
75
+
76
+ describe 'configatron_keys' do
77
+
78
+ it 'should return a list of keys in the store' do
79
+ configatron.abcd.a = 'A'
80
+ configatron.abcd.b = 'B'
81
+ configatron.abcd.c = 'C'
82
+ configatron.abcd.configatron_keys.should == ['a', 'b', 'c']
83
+ end
84
+
85
+ end
86
+
87
+ describe 'heirarchy' do
88
+
89
+ it 'should return a string representing where in the heirarchy the current Store is' do
90
+ configatron.a.b.c.d.heirarchy.should == 'a.b.c.d'
91
+ end
92
+
93
+ end
94
+
95
+ describe 'protect' do
96
+
97
+ it 'should protect a parameter and prevent it from being set' do
98
+ configatron.one = 1
99
+ configatron.protect(:one)
100
+ lambda{configatron.one = 'one'}.should raise_error(Configatron::ProtectedParameter)
101
+ configatron.one.should == 1
102
+ end
103
+
104
+ it 'should protect basic methods' do
105
+ lambda{configatron.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
106
+ lambda{configatron.foo.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
107
+ end
108
+
109
+ it 'should work with nested parameters' do
110
+ configatron.one = 1
111
+ configatron.letters.a = 'A'
112
+ configatron.letters.b = 'B'
113
+ configatron.letters.protect(:a)
114
+ lambda{configatron.letters.a = 'a'}.should raise_error(Configatron::ProtectedParameter)
115
+ configatron.letters.a.should == 'A'
116
+ configatron.protect(:letters)
117
+ lambda{configatron.letters.a = 'a'}.should raise_error(Configatron::ProtectedParameter)
118
+ lambda{configatron.letters = 'letter'}.should raise_error(Configatron::ProtectedParameter)
119
+ end
120
+
121
+ it 'should work with configure_from_hash' do
122
+ configatron.one = 1
123
+ configatron.letters.a = 'A'
124
+ configatron.letters.b = 'B'
125
+ configatron.letters.protect(:a)
126
+ lambda{configatron.configure_from_hash(:letters => {:a => 'a'})}.should raise_error(Configatron::ProtectedParameter)
127
+ configatron.letters.a.should == 'A'
128
+ configatron.protect(:letters)
129
+ lambda{configatron.letters.configure_from_hash(:a => 'a')}.should raise_error(Configatron::ProtectedParameter)
130
+ lambda{configatron.configure_from_hash(:letters => 'letters')}.should raise_error(Configatron::ProtectedParameter)
131
+ end
132
+
133
+ it "should be able to protect all parameters at once" do
134
+ configatron.one = 1
135
+ configatron.letters.a = 'A'
136
+ configatron.letters.b = 'B'
137
+ configatron.protect_all!
138
+ [:a,:b].each do |l|
139
+ lambda{configatron.configure_from_hash(:letters => {l => l.to_s})}.should raise_error(Configatron::ProtectedParameter)
140
+ configatron.letters.send(l).should == l.to_s.upcase
141
+ end
142
+ lambda{configatron.letters.configure_from_hash(:a => 'a')}.should raise_error(Configatron::ProtectedParameter)
143
+ lambda{configatron.configure_from_hash(:letters => 'letters')}.should raise_error(Configatron::ProtectedParameter)
144
+ end
145
+
146
+ it "should be able to unprotect a parameter" do
147
+ configatron.one = 1
148
+ configatron.protect(:one)
149
+ configatron.unprotect(:one)
150
+ lambda{configatron.one = 2}.should_not raise_error
151
+ end
152
+
153
+ it "should be able to unprotect all parameters at once" do
154
+ configatron.one = 1
155
+ configatron.letters.a = 'A'
156
+ configatron.letters.b = 'B'
157
+ configatron.protect_all!
158
+ configatron.unprotect_all!
159
+ lambda{configatron.one = 2}.should_not raise_error
160
+ lambda{configatron.letters.configure_from_hash(:a => 'a')}.should_not raise_error
161
+ end
162
+
163
+ end
164
+
165
+ describe 'lock' do
166
+
167
+ before :each do
168
+ configatron.letters.a = 'A'
169
+ configatron.letters.b = 'B'
170
+ configatron.letters.greek.alpha = 'alpha'
171
+ configatron.lock(:letters)
172
+ end
173
+
174
+ it 'should allow setting of existing parameters in locked parameter' do
175
+ lambda { configatron.letters.a = 'a' }.should_not raise_error
176
+ end
177
+
178
+ it 'should not allow setting of a parameter that is not already set' do
179
+ lambda { configatron.letters.c = 'C' }.should raise_error(Configatron::LockedNamespace)
180
+ end
181
+
182
+ it 'should allow setting of existing parameters in child of locked parameter' do
183
+ lambda { configatron.letters.greek.alpha = 'a' }.should_not raise_error
184
+ end
185
+
186
+ it 'should not allow setting of new parameters in child of locked parameter' do
187
+ lambda { configatron.letters.greek.beta = 'beta' }.should raise_error(Configatron::LockedNamespace)
188
+ end
189
+
190
+ it 'should not affect parameters below the locked namespace' do
191
+ lambda { configatron.one = 1 }.should_not raise_error
192
+ end
193
+
194
+ it 'should raise an ArgumentError if unknown namespace is locked' do
195
+ lambda { configatron.lock(:numbers).should raise_error(ArgumentError) }
196
+ end
197
+
198
+ describe 'then unlock' do
199
+
200
+ before :each do
201
+ configatron.unlock(:letters)
202
+ end
203
+
204
+ it 'should allow setting of new parameter in unlocked namespace' do
205
+ lambda { configatron.letters.d = 'd' }.should_not raise_error
206
+ end
207
+
208
+ it 'should allow setting of new parameter in unlocked namespace\'s child' do
209
+ lambda { configatron.letters.greek.zeta = 'z' }.should_not raise_error
210
+ end
211
+
212
+ it 'should raise an ArgumentError if unknown namespace is unlocked' do
213
+ lambda { configatron.unlock(:numbers).should raise_error(ArgumentError) }
214
+ end
215
+
216
+ end
217
+
218
+ end
219
+
220
+ describe 'temp' do
221
+
222
+ it 'should revert back to the original parameters when the block ends' do
223
+ configatron.one = 1
224
+ configatron.letters.a = 'A'
225
+ configatron.letters.b = 'B'
226
+ configatron.temp do
227
+ configatron.letters.b = 'bb'
228
+ configatron.letters.c = 'c'
229
+ configatron.one.should == 1
230
+ configatron.letters.a.should == 'A'
231
+ configatron.letters.b.should == 'bb'
232
+ configatron.letters.c.should == 'c'
233
+ end
234
+ configatron.one.should == 1
235
+ configatron.letters.a.should == 'A'
236
+ configatron.letters.b.should == 'B'
237
+ configatron.letters.c.should be_nil
238
+ end
239
+
240
+ it 'should take an optional hash of parameters' do
241
+ configatron.one = 1
242
+ configatron.letters.a = 'A'
243
+ configatron.letters.b = 'B'
244
+ configatron.temp(:letters => {:b => 'bb', :c => 'c'}) do
245
+ configatron.one.should == 1
246
+ configatron.letters.a.should == 'A'
247
+ configatron.letters.b.should == 'bb'
248
+ configatron.letters.c.should == 'c'
249
+ end
250
+ configatron.one.should == 1
251
+ configatron.letters.a.should == 'A'
252
+ configatron.letters.b.should == 'B'
253
+ configatron.letters.c.should be_nil
254
+ end
255
+
256
+ it 'should work the same as temp_start/temp_end' do
257
+ configatron.one = 1
258
+ configatron.temp_start
259
+ configatron.one = 'ONE'
260
+ configatron.one.should == 'ONE'
261
+ configatron.temp_end
262
+ configatron.one.should == 1
263
+ end
264
+
265
+ it 'should be able to nest' do
266
+ configatron.one = 1
267
+ configatron.letters.a = 'A'
268
+ configatron.letters.b = 'B'
269
+ configatron.temp do
270
+ configatron.letters.b = 'bb'
271
+ configatron.letters.c = 'c'
272
+ configatron.one.should == 1
273
+ configatron.letters.a.should == 'A'
274
+ configatron.letters.b.should == 'bb'
275
+ configatron.letters.c.should == 'c'
276
+ configatron.temp do
277
+ configatron.letters.b = 'bbb'
278
+ configatron.one.should == 1
279
+ configatron.letters.a.should == 'A'
280
+ configatron.letters.b.should == 'bbb'
281
+ configatron.letters.c.should == 'c'
282
+ end
283
+ end
284
+ configatron.one.should == 1
285
+ configatron.letters.a.should == 'A'
286
+ configatron.letters.b.should == 'B'
287
+ configatron.letters.c.should be_nil
288
+ end
289
+
290
+ end
291
+
292
+ describe 'configure_from_hash' do
293
+
294
+ it 'should configure itself from a hash' do
295
+ configatron.foo.should be_nil
296
+ configatron.configure_from_hash(:foo => :bar)
297
+ configatron.foo.should == :bar
298
+ end
299
+
300
+ it 'should handled deeply nested params' do
301
+ configatron.friends.rachel.should be_nil
302
+ configatron.configure_from_hash(:friends => {:rachel => 'Rachel Green'})
303
+ configatron.friends.rachel.should == 'Rachel Green'
304
+ end
305
+
306
+ it 'should not remove previously defined params' do
307
+ configatron.friends.rachel = 'Rachel Green'
308
+ configatron.friends.ross = 'Ross Gellar'
309
+ configatron.friends.monica = 'Monica Gellar'
310
+ configatron.configure_from_hash(:friends => {:rachel => 'R. Green', :monica => 'Monica Bing'})
311
+ configatron.friends.ross.should == 'Ross Gellar'
312
+ configatron.friends.rachel.should == 'R. Green'
313
+ configatron.friends.monica.should == 'Monica Bing'
314
+ end
315
+
316
+ end
317
+
318
+ describe 'configure_from_yaml' do
319
+
320
+ it 'should configure itself from a yaml file' do
321
+ configatron.futurama.should be_nil
322
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'futurama.yml'))
323
+ configatron.futurama.robots.bender.should == 'Bender The Robot'
324
+ end
325
+
326
+ it 'should not remove previously defined params' do
327
+ configatron.futurama.mutants.leela = 'Leela'
328
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'futurama.yml'))
329
+ configatron.futurama.robots.bender.should == 'Bender The Robot'
330
+ configatron.futurama.mutants.leela = 'Leela'
331
+ end
332
+
333
+ it "should fail silently if the file doesn't exist" do
334
+ lambda{configatron.configure_from_yaml('i_dont_exist.yml')}.should_not raise_error
335
+ end
336
+
337
+ it "should be able to load a specific hash from the file" do
338
+ configatron.others.should be_nil
339
+ configatron.survivors.should be_nil
340
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'lost.yml'), :hash => "survivors")
341
+ configatron.others.should be_nil
342
+ configatron.survivors.should be_nil
343
+ configatron.on_island.jack.should == 'Jack Shepherd'
344
+ end
345
+
346
+ it 'should run the yaml through ERB' do
347
+ configatron.math.should be_nil
348
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'math.yml'))
349
+ configatron.math.should_not be_nil
350
+ configatron.math.four.should == 4
351
+ end
352
+
353
+ it 'should handle merged keys' do
354
+ unless RUBY_VERSION.match(/^2\.0/)
355
+ configatron.food.should be_nil
356
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'merge.yml'))
357
+ configatron.food.should_not be_nil
358
+ configatron.food.list.should == [:apple, :banana, :tomato, :brocolli, :spinach]
359
+ end
360
+ end
361
+
362
+ it "should handle complex yaml" do
363
+ configatron.complex_development.bucket.should be_nil
364
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'complex.yml'))
365
+ configatron.complex_development.bucket.should == 'develop'
366
+ configatron.complex_development.access_key_id.should == 'access_key'
367
+ end
368
+
369
+ end
370
+
371
+ it 'should return a parameter' do
372
+ configatron.foo = :bar
373
+ configatron.foo.should == :bar
374
+ end
375
+
376
+ it 'should return a nested parameter' do
377
+ configatron.children.dylan = 'Dylan Bates'
378
+ configatron.children.dylan.should == 'Dylan Bates'
379
+ end
380
+
381
+ it 'should set a nested parameter and not remove previously defined params' do
382
+ configatron.friends.rachel = 'Rachel Green'
383
+ configatron.friends.rachel.should == 'Rachel Green'
384
+ configatron.friends.ross = 'Ross Gellar'
385
+ configatron.friends.ross.should == 'Ross Gellar'
386
+ configatron.friends.monica = 'Monica Gellar'
387
+ configatron.friends.monica.should == 'Monica Gellar'
388
+ configatron.friends.rachel = 'R. Green'
389
+ configatron.friends.monica = 'Monica Bing'
390
+ configatron.friends.rachel.should == 'R. Green'
391
+ configatron.friends.ross.should == 'Ross Gellar'
392
+ configatron.friends.monica.should == 'Monica Bing'
393
+ end
394
+
395
+ it 'should return the Configatron instance' do
396
+ configatron.should be_is_a(Configatron)
397
+ end
398
+
399
+ describe 'to_hash' do
400
+
401
+ it 'should return a hash of all the params' do
402
+ configatron.one = 1
403
+ configatron.letters.a = 'A'
404
+ configatron.letters.b = 'B'
405
+
406
+ h = configatron.to_hash
407
+ h.should be_an_instance_of(Hash)
408
+ h[:letters].should be_an_instance_of(Hash)
409
+
410
+ h[:one].should == 1
411
+ h[:letters][:b].should == 'B'
412
+ end
413
+
414
+ end
415
+
416
+ describe 'inspect' do
417
+
418
+ it 'should call return the inspect method of the to_hash method' do
419
+ configatron.one = 1
420
+ configatron.letters.a = 'A'
421
+ configatron.letters.b = 'B'
422
+ configatron.numbers.small.one = 1
423
+ configatron.numbers.small.others = [2,3]
424
+ configatron.numbers.big.one.hundred = '100'
425
+
426
+ configatron.inspect.should == %{
427
+ configatron.letters.a = "A"
428
+ configatron.letters.b = "B"
429
+ configatron.numbers.big.one.hundred = "100"
430
+ configatron.numbers.small.one = 1
431
+ configatron.numbers.small.others = [2, 3]
432
+ configatron.one = 1
433
+ }.strip
434
+
435
+ end
436
+
437
+ end
438
+
439
+ describe 'nil?' do
440
+
441
+ it 'should return true if there are no parameters' do
442
+ configatron.should be_nil
443
+ configatron.friends.should be_nil
444
+ end
445
+
446
+ it 'should return true if there are no parameters on a nested parameter' do
447
+ configatron.friends.monica.should be_nil
448
+ end
449
+
450
+ end
451
+
452
+ describe 'retrieve' do
453
+
454
+ it 'should retrieve a parameter' do
455
+ configatron.office = 'Michael'
456
+ configatron.retrieve(:office).should == 'Michael'
457
+ end
458
+
459
+ it 'should return the optional second parameter if the config setting is nil' do
460
+ configatron.retrieve(:office, 'Stanley').should == 'Stanley'
461
+ end
462
+
463
+ it 'should work with a symbol or a string' do
464
+ configatron.office = 'Michael'
465
+ configatron.retrieve(:office).should == 'Michael'
466
+ configatron.retrieve('office').should == 'Michael'
467
+ end
468
+
469
+ it 'should work on nested parameters' do
470
+ configatron.the.office = 'Michael'
471
+ configatron.the.retrieve(:office).should == 'Michael'
472
+ configatron.the.retrieve('office').should == 'Michael'
473
+ end
474
+
475
+ end
476
+
477
+ describe 'remove' do
478
+
479
+ it 'should remove a parameter' do
480
+ configatron.movies = 'Pulp Fiction'
481
+ configatron.movies.should == 'Pulp Fiction'
482
+ configatron.remove(:movies)
483
+ configatron.movies.should be_nil
484
+ end
485
+
486
+ it 'should remove a nested parameter' do
487
+ configatron.the.movies = 'Pulp Fiction'
488
+ configatron.the.movies.should == 'Pulp Fiction'
489
+ configatron.the.remove(:movies)
490
+ configatron.the.movies.should be_nil
491
+ end
492
+
493
+ it 'should work with a symbol or a string' do
494
+ configatron.the.movies = 'Pulp Fiction'
495
+ configatron.the.office = 'Michael'
496
+ configatron.the.remove(:movies)
497
+ configatron.the.movies.should be_nil
498
+ configatron.the.remove('office')
499
+ configatron.the.office.should be_nil
500
+ end
501
+
502
+ it 'should remove all sub-parameters' do
503
+ configatron.the.movies = 'Pulp Fiction'
504
+ configatron.the.office = 'Michael'
505
+ configatron.remove(:the)
506
+ configatron.the.should be_nil
507
+ configatron.the.movies.should be_nil
508
+ end
509
+
510
+ end
511
+
512
+ describe 'set_default' do
513
+
514
+ it 'should set a default parameter value' do
515
+ configatron.set_default(:movies, 'Pulp Fiction')
516
+ configatron.movies.should == 'Pulp Fiction'
517
+ end
518
+
519
+ it 'should set a default parameter value for a nested parameter' do
520
+ configatron.the.set_default(:movies, 'Pulp Fiction')
521
+ configatron.the.movies.should == 'Pulp Fiction'
522
+ end
523
+
524
+ it 'should not set the parameter if it is already set' do
525
+ configatron.movies = 'Transformers'
526
+ configatron.set_default(:movies, 'Pulp Fiction')
527
+ configatron.movies.should == 'Transformers'
528
+ end
529
+
530
+ it 'should not set the nested parameter if it is already set' do
531
+ configatron.the.movies = 'Transformers'
532
+ configatron.the.set_default(:movies, 'Pulp Fiction')
533
+ configatron.the.movies.should == 'Transformers'
534
+ end
535
+
536
+ end
537
+
538
+ describe 'reset!' do
539
+
540
+ it 'should clear out all parameter' do
541
+ configatron.one = 1
542
+ configatron.letters.a = 'A'
543
+ configatron.letters.b = 'B'
544
+ configatron.one.should == 1
545
+ configatron.letters.a.should == 'A'
546
+ configatron.reset!
547
+ configatron.one.should be_nil
548
+ configatron.letters.a.should be_nil
549
+ end
550
+
551
+ end
552
+
553
+ describe :blank? do
554
+
555
+ context "uninitialized option" do
556
+ specify { configatron.foo.bar.should be_blank }
557
+ end
558
+
559
+ context "nil option" do
560
+ before { configatron.foo.bar = nil }
561
+ specify { configatron.foo.bar.should be_blank }
562
+ end
563
+
564
+ context "false option" do
565
+ before { configatron.foo.bar = false }
566
+ specify { configatron.foo.bar.should be_blank }
567
+ end
568
+
569
+ context "empty string option" do
570
+ before { configatron.foo.bar = "" }
571
+ specify { configatron.foo.bar.should be_blank }
572
+ end
573
+
574
+ context "empty hash option" do
575
+ before { configatron.foo.bar = {} }
576
+ specify { configatron.foo.bar.should be_blank }
577
+ end
578
+
579
+ context "empty array option" do
580
+ before { configatron.foo.bar = [] }
581
+ specify { configatron.foo.bar.should be_blank }
582
+ end
583
+
584
+ context "defined option" do
585
+ before { configatron.foo.bar = 'asd' }
586
+ subject { configatron.foo.bar }
587
+ it { should_not be_blank }
588
+ it { should == 'asd' }
589
+ end
590
+
591
+ end
592
+
593
+
594
+ describe "boolean test" do
595
+
596
+ context "nil option" do
597
+ before { configatron.foo.bar = nil }
598
+ specify { configatron.foo.bar?.should be_false }
599
+ end
600
+
601
+ context "false option" do
602
+ before { configatron.foo.bar = false }
603
+ specify { configatron.foo.bar?.should be_false }
604
+ end
605
+
606
+ context "string option" do
607
+ before { configatron.foo.bar = 'asd' }
608
+ specify { configatron.foo.bar?.should be_true }
609
+ end
610
+
611
+ end
612
+
613
+ end