@@ -951,13 +951,168 @@ def nested_configuration_example conf
951
951
952
952
end # "v1.0"
953
953
954
- #context 'v1.1' do
955
- #
956
- # context 'merge' do
957
- #
958
- # end
959
- #
960
- #end #v1.1
954
+ def simple_config_1
955
+ Configuration . new do
956
+ alpha 1
957
+ bravo 'one'
958
+ charlie 1.0
959
+ delta :one
960
+ end
961
+ end
962
+
963
+ def simple_config_1_example conf
964
+ conf . should_not be_nil
965
+ conf . alpha . should == 1 and conf . alpha . should be_a Fixnum
966
+ conf . bravo . should == "one" and conf . bravo . should be_a String
967
+ conf . charlie . should == 1.0 and conf . charlie . should be_a Float
968
+ conf . delta . should == :one and conf . delta . should be_a Symbol
969
+ end
970
+
971
+ def simple_config_2
972
+ Configuration . new do
973
+ echo 2
974
+ foxtrot 'two'
975
+ hotel 2.0
976
+ india :two
977
+ end
978
+ end
979
+
980
+ def simple_config_2_example conf
981
+ conf . should_not be_nil
982
+ conf . echo . should == 2 and conf . echo . should be_a Fixnum
983
+ conf . foxtrot . should == "two" and conf . foxtrot . should be_a String
984
+ conf . hotel . should == 2.0 and conf . hotel . should be_a Float
985
+ conf . india . should == :two and conf . india . should be_a Symbol
986
+ conf [ 'echo' ]
987
+ #and conf[:echo].should be_a Fixnum
988
+
989
+ end
990
+
991
+ def simple_config_3
992
+ Configuration . new do
993
+ juliet 3
994
+ kilo 'three'
995
+ lima 3.0
996
+ mike :three
997
+ end
998
+ end
999
+
1000
+ def simple_config_3_example conf
1001
+ conf . should_not be_nil
1002
+ conf . juliet . should == 3 and conf . juliet . should be_a Fixnum
1003
+ conf . kilo . should == "three" and conf . kilo . should be_a String
1004
+ conf . lima . should == 3.0 and conf . lima . should be_a Float
1005
+ conf . mike . should == :three and conf . mike . should be_a Symbol
1006
+ end
1007
+
1008
+ context 'v1.1' do
1009
+
1010
+ context 'options' do
1011
+
1012
+ it 'have defaults at Configuration creation' do
1013
+ conf = Configuration . new
1014
+ conf . _options [ :blankslate ] . should be true
1015
+ conf . _options [ :case_sensitive ] . should be true
1016
+ end
1017
+
1018
+ it 'are accepted at Configuration creation' do
1019
+ conf = Configuration . new nil , :blankslate => false , :case_sensitive => false
1020
+ conf . _options [ :blankslate ] . should be false
1021
+ conf . _options [ :case_sensitive ] . should be false
1022
+ end
1023
+
1024
+ end
1025
+
1026
+ context 'wildcard *' do
1027
+
1028
+ it 'returns an empty ConfigurationDelegator for subject with no child configurations' do
1029
+ conf = simple_config_1
1030
+ simple_config_1_example conf
1031
+ delegator = conf . *
1032
+ delegator . should be_a ConfigurationDelegator
1033
+ delegator . should be_empty
1034
+ end
1035
+
1036
+ it 'returns ConfigurationDelegator containing child configurations for subject' do
1037
+ conf = simple_config_1
1038
+ conf . nested2 = simple_config_2
1039
+ conf . nested3 = simple_config_3
1040
+ simple_config_1_example conf
1041
+ simple_config_2_example conf . nested2
1042
+ simple_config_3_example conf . nested3
1043
+ delegator = conf . *
1044
+ delegator . should be_a ConfigurationDelegator
1045
+ delegator . size . should be 2
1046
+ delegator [ 0 ] . should be conf . nested2
1047
+ delegator [ 1 ] . should be conf . nested3
1048
+ end
1049
+
1050
+ end
1051
+
1052
+ context 'ConfigurationDelegator' do
1053
+
1054
+ it 'can be created with no child configurations' do
1055
+ delegator = ConfigurationDelegator . new [ ]
1056
+ delegator . should be_a ConfigurationDelegator
1057
+ delegator . should be_empty
1058
+ end
1059
+
1060
+ context 'wildcard *' do
1061
+
1062
+ # todo: question : should wildcard return nil for already empty ConfigurationDelegator / overshoot ?
1063
+
1064
+ it 'returns an empty ConfigurationDelegator for ConfigurationDelegator with no child configurations' do
1065
+ conf = simple_config_1
1066
+ conf . nested2 = simple_config_2
1067
+ conf . nested3 = simple_config_3
1068
+ simple_config_1_example conf
1069
+ simple_config_2_example conf . nested2
1070
+ simple_config_3_example conf . nested3
1071
+ delegator = conf . *. *
1072
+ delegator . should be_a ConfigurationDelegator
1073
+ delegator . should be_empty
1074
+ end
1075
+
1076
+ it 'returns an empty ConfigurationDelegator when overshoots' do
1077
+ conf = simple_config_1
1078
+ conf . nested2 = simple_config_2
1079
+ conf . nested3 = simple_config_3
1080
+ simple_config_1_example conf
1081
+ simple_config_2_example conf . nested2
1082
+ simple_config_3_example conf . nested3
1083
+ delegator = conf . *. *. *. *. *. *. *. *. *
1084
+ delegator . should be_a ConfigurationDelegator
1085
+ delegator . should be_empty
1086
+ end
1087
+
1088
+ it 'returns ConfigurationDelegator containing child configurations for ConfigurationDelegator' do
1089
+ conf = simple_config_1
1090
+ conf . nested2 = simple_config_2
1091
+ conf . nested3 = simple_config_3
1092
+ conf . nested2 . nested2 = simple_config_2
1093
+ conf . nested2 . nested3 = simple_config_3
1094
+ conf . nested3 . nested2 = simple_config_2
1095
+ conf . nested3 . nested3 = simple_config_3
1096
+ simple_config_1_example conf
1097
+ simple_config_2_example conf . nested2
1098
+ simple_config_2_example conf . nested2 . nested2
1099
+ simple_config_2_example conf . nested3 . nested2
1100
+ simple_config_3_example conf . nested3
1101
+ simple_config_3_example conf . nested2 . nested3
1102
+ simple_config_3_example conf . nested3 . nested3
1103
+ delegator = conf . *. *
1104
+ delegator . size . should be 4
1105
+ delegator [ 0 ] . should be conf . nested2 . nested2
1106
+ delegator [ 1 ] . should be conf . nested2 . nested3
1107
+ delegator [ 2 ] . should be conf . nested3 . nested2
1108
+ delegator [ 3 ] . should be conf . nested3 . nested3
1109
+ end
1110
+
1111
+ end # wildcard *
1112
+
1113
+ end # ConfigurationDelagator
1114
+
1115
+ end #v1.1
961
1116
962
1117
end
963
1118
0 commit comments