configy 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/configy_test.rb CHANGED
@@ -1,124 +1,40 @@
1
1
  require 'test_helper'
2
2
 
3
- class ConfigyTest < Test::Unit::TestCase
3
+ class ConfigyTest < MiniTest::Unit::TestCase
4
+
4
5
  def setup
5
- @dir = File.dirname(__FILE__) + "/"
6
- @files = []
7
- end
8
-
9
- def test_should_read_from_yml
10
- test_config 'common' => {'a' => '1', 'b' => '2'} do |file, hash|
11
- config = Configy::Configuration.new(file)
12
- assert_equal_with_hash config, hash['common']
13
- end
14
- end
15
-
16
- def test_should_ignore_non_existent_file
17
- config = Configy::Configuration.new('nonexsistentfile')
18
- assert_not_nil config
19
- end
20
-
21
- def test_should_igonre_non_existent_section
22
- test_config 'common' => {'a' => '1', 'b' => '2' } do |file, hash|
23
- config = Configy::Configuration.new(file)
24
- config.use_section!('nonexistentsection')
25
- assert_equal config.b, '2'
26
- end
27
- end
28
-
29
- def test_should_parse_yaml_with_erb
30
- test_config 'common' => {'a' => '1', 'b' => '<%= 2 + 2 %>' } do |file, hash|
31
- config = Configy::Configuration.new(file)
32
- assert_equal config.b, 4
33
- end
34
- end
35
-
36
- def test_should_override_params_with_given_section
37
- test_config 'common' => {'a' => '1', 'b' => '<%= 2 + 2 %>'},
38
- 'special' => {'a' => 1, 'b' => 5 } do |file, hash|
39
- config = Configy::Configuration.new(file)
40
- config.use_section!('special')
41
- assert_equal_with_hash config, hash['special']
42
- end
43
- test_config 'common' => {'a' => '1', 'b' => '<%= 2 + 2 %>'},
44
- 'special' => {'b' => 5 } do |file, hash|
45
- config = Configy::Configuration.new(file)
46
- config.use_section!('special')
47
- assert_equal_with_hash config, {'a' => '1', 'b' => 5}
48
- end
6
+ Configy.load_path = scratch_dir
7
+ Configy.cache_config = nil
49
8
  end
50
-
51
- def test_should_ovveride_params_with_another_file
52
- test_config({'common' => {'a' => '1', 'b' => '<%= 2 + 2 %>'},
53
- 'special' => {'b' => 5 }}, 'config') do |file1, hash1|
54
- test_config({'common' => {'a' => '2'},
55
- 'special' => {'b' => 8 }}, 'config.local') do |file2, hash2|
56
- config = Configy::Configuration.new(file1)
57
- assert_equal_with_hash config, {'a' => '1', 'b' => 4}
58
- config.use_file!(file2)
59
- assert_equal_with_hash config, {'a' => '2', 'b' => 4}
60
- end
61
- end
62
- end
63
-
64
- def test_should_ovveride_params_with_another_file_and_use_proper_section
65
- test_config({'common' => {'a' => '1', 'b' => '<%= 2 + 2 %>', 'c' => 2},
66
- 'special' => {'b' => 5, 'd' => 6 },
67
- 'extra' => {'f' => 4, 'a' => 8}}, 'config') do |file1, hash1|
68
- test_config({'common' => {'a' => '2'},
69
- 'special' => {'b' => 8 }}, 'config.local') do |file2, hash2|
70
- config = Configy::Configuration.new
71
- config.use_file!(file1)
72
- config.use_file!(file2)
73
- config.use_section!('special')
74
- assert_equal_with_hash config, {'a' => '2', 'b' => 8, 'c' => 2, 'd' => 6}
75
- end
76
- end
77
- end
78
-
9
+
79
10
  def test_camelize
80
11
  assert_equal 'Config', Configy.camelize('config')
81
12
  assert_equal 'SomeConfig', Configy.camelize('some_config')
82
13
  assert_equal 'SomeOtherConfig', Configy.camelize('some-other_config')
83
14
  end
84
-
85
- def test_should_create_configuration_via_create
86
- Configy.load_path = @dir
87
- test_config( {'common' => {'a' => '1', 'b' => '2' }}, 'some_config' ) do |file, hash|
88
- Configy.create('some_config')
89
- assert_equal SomeConfig.b, '2'
90
- end
91
- end
92
-
93
- def teardown
94
- begin
95
- FileUtils.rm @files
96
- rescue
15
+
16
+ def test_should_create_a_configuration_class_based_on_a_yaml_file
17
+ with_config_file( {'common' => {'a' => '1', 'b' => '2' }}, 'app_config' ) do |file, hash|
18
+ Configy.create('app_config')
19
+ assert Object.const_defined?(:AppConfig)
20
+ assert_equal AppConfig.b, '2'
97
21
  end
98
22
  end
99
-
100
- protected
101
-
102
- def file_path(file)
103
- @dir + file + '.yml'
104
- end
105
-
106
- def create_config_file(file, hash)
107
- file = @dir + file + '.yml'
108
- @files << file
109
- File.open(file, 'w') do |f|
110
- f.write hash.to_yaml
111
- end
112
- end
113
-
114
- def assert_equal_with_hash(config, hash)
115
- hash.each do |key, value|
116
- assert_equal config.send(key), value
117
- end
118
- end
119
-
120
- def test_config(hash, file = 'config', &blk)
121
- create_config_file file, hash
122
- blk.call(file_path(file), hash)
123
- end
23
+
24
+ def test_cache_config_always_defaults_to_false
25
+ Configy.section = 'production'
26
+ assert_equal false, Configy.cache_config
27
+
28
+ Configy.section = 'development'
29
+ assert_equal false, Configy.cache_config
30
+ end
31
+
32
+ def test_should_be_able_to_manually_set_cache_config
33
+ Configy.cache_config = true
34
+ Configy.create('dummy')
35
+
36
+ assert_equal true, Configy.cache_config
37
+ assert_equal true, Dummy.cache_config?
38
+ end
39
+
124
40
  end
@@ -0,0 +1,974 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 44
13
+ 5
14
+ 7
15
+ 0
16
+ 64
17
+ 47
18
+ 49
19
+ 1
20
+ 1
21
+ 15
22
+ 99
23
+ 7
24
+ 2
25
+ 45
26
+ 3
27
+ 4
28
+ 43
29
+ 5
30
+ 43
31
+ 6
32
+ 65
33
+ 49
34
+ 7
35
+ 3
36
+ 13
37
+ 99
38
+ 12
39
+ 7
40
+ 8
41
+ 12
42
+ 7
43
+ 9
44
+ 12
45
+ 65
46
+ 12
47
+ 49
48
+ 10
49
+ 4
50
+ 15
51
+ 49
52
+ 8
53
+ 0
54
+ 15
55
+ 2
56
+ 11
57
+ I
58
+ 6
59
+ I
60
+ 0
61
+ I
62
+ 0
63
+ I
64
+ 0
65
+ n
66
+ p
67
+ 11
68
+ s
69
+ 11
70
+ test_helper
71
+ x
72
+ 7
73
+ require
74
+ x
75
+ 11
76
+ ConfigyTest
77
+ x
78
+ 8
79
+ MiniTest
80
+ n
81
+ x
82
+ 4
83
+ Unit
84
+ x
85
+ 8
86
+ TestCase
87
+ x
88
+ 10
89
+ open_class
90
+ x
91
+ 14
92
+ __class_init__
93
+ M
94
+ 1
95
+ n
96
+ n
97
+ x
98
+ 11
99
+ ConfigyTest
100
+ i
101
+ 72
102
+ 5
103
+ 66
104
+ 99
105
+ 7
106
+ 0
107
+ 7
108
+ 1
109
+ 65
110
+ 67
111
+ 49
112
+ 2
113
+ 0
114
+ 49
115
+ 3
116
+ 4
117
+ 15
118
+ 99
119
+ 7
120
+ 4
121
+ 7
122
+ 5
123
+ 65
124
+ 67
125
+ 49
126
+ 2
127
+ 0
128
+ 49
129
+ 3
130
+ 4
131
+ 15
132
+ 99
133
+ 7
134
+ 6
135
+ 7
136
+ 7
137
+ 65
138
+ 67
139
+ 49
140
+ 2
141
+ 0
142
+ 49
143
+ 3
144
+ 4
145
+ 15
146
+ 99
147
+ 7
148
+ 8
149
+ 7
150
+ 9
151
+ 65
152
+ 67
153
+ 49
154
+ 2
155
+ 0
156
+ 49
157
+ 3
158
+ 4
159
+ 15
160
+ 99
161
+ 7
162
+ 10
163
+ 7
164
+ 11
165
+ 65
166
+ 67
167
+ 49
168
+ 2
169
+ 0
170
+ 49
171
+ 3
172
+ 4
173
+ 11
174
+ I
175
+ 5
176
+ I
177
+ 0
178
+ I
179
+ 0
180
+ I
181
+ 0
182
+ n
183
+ p
184
+ 12
185
+ x
186
+ 5
187
+ setup
188
+ M
189
+ 1
190
+ n
191
+ n
192
+ x
193
+ 5
194
+ setup
195
+ i
196
+ 26
197
+ 45
198
+ 0
199
+ 1
200
+ 5
201
+ 48
202
+ 2
203
+ 13
204
+ 18
205
+ 2
206
+ 49
207
+ 3
208
+ 1
209
+ 15
210
+ 15
211
+ 45
212
+ 0
213
+ 4
214
+ 1
215
+ 13
216
+ 18
217
+ 2
218
+ 49
219
+ 5
220
+ 1
221
+ 15
222
+ 11
223
+ I
224
+ 3
225
+ I
226
+ 0
227
+ I
228
+ 0
229
+ I
230
+ 0
231
+ n
232
+ p
233
+ 6
234
+ x
235
+ 7
236
+ Configy
237
+ n
238
+ x
239
+ 11
240
+ scratch_dir
241
+ x
242
+ 10
243
+ load_path=
244
+ n
245
+ x
246
+ 13
247
+ cache_config=
248
+ p
249
+ 7
250
+ I
251
+ 0
252
+ I
253
+ 5
254
+ I
255
+ 0
256
+ I
257
+ 6
258
+ I
259
+ e
260
+ I
261
+ 7
262
+ I
263
+ 1a
264
+ x
265
+ 61
266
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
267
+ p
268
+ 0
269
+ x
270
+ 17
271
+ method_visibility
272
+ x
273
+ 15
274
+ add_defn_method
275
+ x
276
+ 13
277
+ test_camelize
278
+ M
279
+ 1
280
+ n
281
+ n
282
+ x
283
+ 13
284
+ test_camelize
285
+ i
286
+ 54
287
+ 5
288
+ 7
289
+ 0
290
+ 64
291
+ 45
292
+ 1
293
+ 2
294
+ 7
295
+ 3
296
+ 64
297
+ 49
298
+ 4
299
+ 1
300
+ 47
301
+ 49
302
+ 5
303
+ 2
304
+ 15
305
+ 5
306
+ 7
307
+ 6
308
+ 64
309
+ 45
310
+ 1
311
+ 7
312
+ 7
313
+ 8
314
+ 64
315
+ 49
316
+ 4
317
+ 1
318
+ 47
319
+ 49
320
+ 5
321
+ 2
322
+ 15
323
+ 5
324
+ 7
325
+ 9
326
+ 64
327
+ 45
328
+ 1
329
+ 10
330
+ 7
331
+ 11
332
+ 64
333
+ 49
334
+ 4
335
+ 1
336
+ 47
337
+ 49
338
+ 5
339
+ 2
340
+ 11
341
+ I
342
+ 4
343
+ I
344
+ 0
345
+ I
346
+ 0
347
+ I
348
+ 0
349
+ n
350
+ p
351
+ 12
352
+ s
353
+ 6
354
+ Config
355
+ x
356
+ 7
357
+ Configy
358
+ n
359
+ s
360
+ 6
361
+ config
362
+ x
363
+ 8
364
+ camelize
365
+ x
366
+ 12
367
+ assert_equal
368
+ s
369
+ 10
370
+ SomeConfig
371
+ n
372
+ s
373
+ 11
374
+ some_config
375
+ s
376
+ 15
377
+ SomeOtherConfig
378
+ n
379
+ s
380
+ 17
381
+ some-other_config
382
+ p
383
+ 9
384
+ I
385
+ 0
386
+ I
387
+ a
388
+ I
389
+ 0
390
+ I
391
+ b
392
+ I
393
+ 12
394
+ I
395
+ c
396
+ I
397
+ 24
398
+ I
399
+ d
400
+ I
401
+ 36
402
+ x
403
+ 61
404
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
405
+ p
406
+ 0
407
+ x
408
+ 61
409
+ test_should_create_a_configuration_class_based_on_a_yaml_file
410
+ M
411
+ 1
412
+ n
413
+ n
414
+ x
415
+ 61
416
+ test_should_create_a_configuration_class_based_on_a_yaml_file
417
+ i
418
+ 55
419
+ 5
420
+ 44
421
+ 43
422
+ 0
423
+ 79
424
+ 49
425
+ 1
426
+ 1
427
+ 13
428
+ 7
429
+ 2
430
+ 64
431
+ 44
432
+ 43
433
+ 0
434
+ 80
435
+ 49
436
+ 1
437
+ 1
438
+ 13
439
+ 7
440
+ 3
441
+ 64
442
+ 7
443
+ 4
444
+ 64
445
+ 49
446
+ 5
447
+ 2
448
+ 15
449
+ 13
450
+ 7
451
+ 6
452
+ 64
453
+ 7
454
+ 7
455
+ 64
456
+ 49
457
+ 5
458
+ 2
459
+ 15
460
+ 49
461
+ 5
462
+ 2
463
+ 15
464
+ 7
465
+ 8
466
+ 64
467
+ 56
468
+ 9
469
+ 47
470
+ 50
471
+ 10
472
+ 2
473
+ 11
474
+ I
475
+ 8
476
+ I
477
+ 0
478
+ I
479
+ 0
480
+ I
481
+ 0
482
+ n
483
+ p
484
+ 11
485
+ x
486
+ 4
487
+ Hash
488
+ x
489
+ 16
490
+ new_from_literal
491
+ s
492
+ 6
493
+ common
494
+ s
495
+ 1
496
+ a
497
+ s
498
+ 1
499
+ 1
500
+ x
501
+ 3
502
+ []=
503
+ s
504
+ 1
505
+ b
506
+ s
507
+ 1
508
+ 2
509
+ s
510
+ 10
511
+ app_config
512
+ M
513
+ 1
514
+ p
515
+ 2
516
+ x
517
+ 9
518
+ for_block
519
+ t
520
+ n
521
+ x
522
+ 61
523
+ test_should_create_a_configuration_class_based_on_a_yaml_file
524
+ i
525
+ 49
526
+ 58
527
+ 37
528
+ 19
529
+ 0
530
+ 15
531
+ 37
532
+ 19
533
+ 1
534
+ 15
535
+ 15
536
+ 45
537
+ 0
538
+ 1
539
+ 7
540
+ 2
541
+ 64
542
+ 49
543
+ 3
544
+ 1
545
+ 15
546
+ 5
547
+ 45
548
+ 4
549
+ 5
550
+ 7
551
+ 6
552
+ 49
553
+ 7
554
+ 1
555
+ 47
556
+ 49
557
+ 8
558
+ 1
559
+ 15
560
+ 5
561
+ 45
562
+ 6
563
+ 9
564
+ 49
565
+ 10
566
+ 0
567
+ 7
568
+ 11
569
+ 64
570
+ 47
571
+ 49
572
+ 12
573
+ 2
574
+ 11
575
+ I
576
+ 6
577
+ I
578
+ 2
579
+ I
580
+ 2
581
+ I
582
+ 2
583
+ n
584
+ p
585
+ 13
586
+ x
587
+ 7
588
+ Configy
589
+ n
590
+ s
591
+ 10
592
+ app_config
593
+ x
594
+ 6
595
+ create
596
+ x
597
+ 6
598
+ Object
599
+ n
600
+ x
601
+ 9
602
+ AppConfig
603
+ x
604
+ 14
605
+ const_defined?
606
+ x
607
+ 6
608
+ assert
609
+ n
610
+ x
611
+ 1
612
+ b
613
+ s
614
+ 1
615
+ 2
616
+ x
617
+ 12
618
+ assert_equal
619
+ p
620
+ 9
621
+ I
622
+ 0
623
+ I
624
+ 11
625
+ I
626
+ a
627
+ I
628
+ 12
629
+ I
630
+ 14
631
+ I
632
+ 13
633
+ I
634
+ 22
635
+ I
636
+ 14
637
+ I
638
+ 31
639
+ x
640
+ 61
641
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
642
+ p
643
+ 2
644
+ x
645
+ 4
646
+ file
647
+ x
648
+ 4
649
+ hash
650
+ x
651
+ 16
652
+ with_config_file
653
+ p
654
+ 5
655
+ I
656
+ 0
657
+ I
658
+ 10
659
+ I
660
+ 0
661
+ I
662
+ 11
663
+ I
664
+ 37
665
+ x
666
+ 61
667
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
668
+ p
669
+ 0
670
+ x
671
+ 42
672
+ test_cache_config_always_defaults_to_false
673
+ M
674
+ 1
675
+ n
676
+ n
677
+ x
678
+ 42
679
+ test_cache_config_always_defaults_to_false
680
+ i
681
+ 54
682
+ 45
683
+ 0
684
+ 1
685
+ 7
686
+ 2
687
+ 64
688
+ 13
689
+ 18
690
+ 2
691
+ 49
692
+ 3
693
+ 1
694
+ 15
695
+ 15
696
+ 5
697
+ 3
698
+ 45
699
+ 0
700
+ 4
701
+ 49
702
+ 5
703
+ 0
704
+ 47
705
+ 49
706
+ 6
707
+ 2
708
+ 15
709
+ 45
710
+ 0
711
+ 7
712
+ 7
713
+ 8
714
+ 64
715
+ 13
716
+ 18
717
+ 2
718
+ 49
719
+ 3
720
+ 1
721
+ 15
722
+ 15
723
+ 5
724
+ 3
725
+ 45
726
+ 0
727
+ 9
728
+ 49
729
+ 5
730
+ 0
731
+ 47
732
+ 49
733
+ 6
734
+ 2
735
+ 11
736
+ I
737
+ 3
738
+ I
739
+ 0
740
+ I
741
+ 0
742
+ I
743
+ 0
744
+ n
745
+ p
746
+ 10
747
+ x
748
+ 7
749
+ Configy
750
+ n
751
+ s
752
+ 10
753
+ production
754
+ x
755
+ 8
756
+ section=
757
+ n
758
+ x
759
+ 12
760
+ cache_config
761
+ x
762
+ 12
763
+ assert_equal
764
+ n
765
+ s
766
+ 11
767
+ development
768
+ n
769
+ p
770
+ 11
771
+ I
772
+ 0
773
+ I
774
+ 18
775
+ I
776
+ 0
777
+ I
778
+ 19
779
+ I
780
+ e
781
+ I
782
+ 1a
783
+ I
784
+ 1b
785
+ I
786
+ 1c
787
+ I
788
+ 29
789
+ I
790
+ 1d
791
+ I
792
+ 36
793
+ x
794
+ 61
795
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
796
+ p
797
+ 0
798
+ x
799
+ 48
800
+ test_should_be_able_to_manually_set_cache_config
801
+ M
802
+ 1
803
+ n
804
+ n
805
+ x
806
+ 48
807
+ test_should_be_able_to_manually_set_cache_config
808
+ i
809
+ 48
810
+ 45
811
+ 0
812
+ 1
813
+ 2
814
+ 13
815
+ 18
816
+ 2
817
+ 49
818
+ 2
819
+ 1
820
+ 15
821
+ 15
822
+ 45
823
+ 0
824
+ 3
825
+ 7
826
+ 4
827
+ 64
828
+ 49
829
+ 5
830
+ 1
831
+ 15
832
+ 5
833
+ 2
834
+ 45
835
+ 0
836
+ 6
837
+ 49
838
+ 7
839
+ 0
840
+ 47
841
+ 49
842
+ 8
843
+ 2
844
+ 15
845
+ 5
846
+ 2
847
+ 45
848
+ 9
849
+ 10
850
+ 49
851
+ 11
852
+ 0
853
+ 47
854
+ 49
855
+ 8
856
+ 2
857
+ 11
858
+ I
859
+ 3
860
+ I
861
+ 0
862
+ I
863
+ 0
864
+ I
865
+ 0
866
+ n
867
+ p
868
+ 12
869
+ x
870
+ 7
871
+ Configy
872
+ n
873
+ x
874
+ 13
875
+ cache_config=
876
+ n
877
+ s
878
+ 5
879
+ dummy
880
+ x
881
+ 6
882
+ create
883
+ n
884
+ x
885
+ 12
886
+ cache_config
887
+ x
888
+ 12
889
+ assert_equal
890
+ x
891
+ 5
892
+ Dummy
893
+ n
894
+ x
895
+ 13
896
+ cache_config?
897
+ p
898
+ 11
899
+ I
900
+ 0
901
+ I
902
+ 20
903
+ I
904
+ 0
905
+ I
906
+ 21
907
+ I
908
+ c
909
+ I
910
+ 22
911
+ I
912
+ 16
913
+ I
914
+ 24
915
+ I
916
+ 23
917
+ I
918
+ 25
919
+ I
920
+ 30
921
+ x
922
+ 61
923
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
924
+ p
925
+ 0
926
+ p
927
+ 11
928
+ I
929
+ 2
930
+ I
931
+ 5
932
+ I
933
+ 10
934
+ I
935
+ a
936
+ I
937
+ 1e
938
+ I
939
+ 10
940
+ I
941
+ 2c
942
+ I
943
+ 18
944
+ I
945
+ 3a
946
+ I
947
+ 20
948
+ I
949
+ 48
950
+ x
951
+ 61
952
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
953
+ p
954
+ 0
955
+ x
956
+ 13
957
+ attach_method
958
+ p
959
+ 5
960
+ I
961
+ 0
962
+ I
963
+ 1
964
+ I
965
+ 9
966
+ I
967
+ 3
968
+ I
969
+ 2c
970
+ x
971
+ 61
972
+ /Users/gabevarela/work/ruby/gems/configy/test/configy_test.rb
973
+ p
974
+ 0