cascading_classes 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +165 -64
- data/spec/basics/basic_spec.rb +71 -76
- data/spec/basics/block_spec.rb +10 -10
- data/spec/basics/container_spec.rb +90 -90
- data/spec/basics/inherit_spec.rb +156 -156
- data/spec/basics/proc_spec.rb +94 -94
- data/spec/class_helper_methods/parents_for_spec.rb +5 -5
- data/spec/custom_classes/hash_like_spec.rb +11 -11
- data/spec/helper_spec.rb +11 -11
- data/spec/instances/basics.rb +39 -39
- data/spec/preset_classes/array_spec.rb +39 -39
- data/spec/preset_classes/hash_spec.rb +38 -38
- data/spec/preset_classes/strings.rb +53 -53
- data/spec/preset_classes/undefined.rb +4 -4
- data/spec/usage/block_spec.rb +6 -6
- data/spec/usage/proc_spec.rb +8 -8
- data/todo +21 -0
- metadata +1 -2
- data/README-part-ii.md +0 -1020
data/spec/basics/block_spec.rb
CHANGED
@@ -23,19 +23,19 @@ describe "block given" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "takes two params: value of self, parent classes" do
|
26
|
-
A.score{|my_score, parents| my_score}.
|
26
|
+
A.score{|my_score, parents| my_score}.should == A.score
|
27
27
|
|
28
28
|
B.score = 28.2
|
29
|
-
B.score{|my_score, parents| my_score}.
|
29
|
+
B.score{|my_score, parents| my_score}.should == B.score
|
30
30
|
|
31
|
-
A.new.score{|my_score| my_score}.
|
32
|
-
B.new.score{|my_score| my_score}.
|
31
|
+
A.new.score{|my_score| my_score}.should == A.new.score
|
32
|
+
B.new.score{|my_score| my_score}.should == B.new.score
|
33
33
|
|
34
|
-
A.score{|my_score, parents| parents}.
|
35
|
-
B.score{|my_score, parents| parents}.
|
34
|
+
A.score{|my_score, parents| parents}.should == []
|
35
|
+
B.score{|my_score, parents| parents}.should == [A]
|
36
36
|
|
37
|
-
A.new.score{|my_score, parents| parents}.
|
38
|
-
B.new.score{|my_score, parents| parents}.
|
37
|
+
A.new.score{|my_score, parents| parents}.should == [A]
|
38
|
+
B.new.score{|my_score, parents| parents}.should == [B, A]
|
39
39
|
|
40
40
|
=begin
|
41
41
|
what_score, which_parents = nil, nil
|
@@ -45,8 +45,8 @@ describe "block given" do
|
|
45
45
|
which_parents = parents
|
46
46
|
}
|
47
47
|
|
48
|
-
what_score.
|
49
|
-
which_parents.
|
48
|
+
what_score.should ==(B.score)
|
49
|
+
which_parents.should ==([A])
|
50
50
|
=end
|
51
51
|
end
|
52
52
|
end
|
@@ -23,16 +23,16 @@ describe "container types: typical" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "does not inherit by default" do
|
26
|
-
@props[:urls][:inherit].
|
27
|
-
@props[:name][:inherit].
|
26
|
+
@props[:urls][:inherit].should == false
|
27
|
+
@props[:name][:inherit].should == false
|
28
28
|
|
29
|
-
A.urls.
|
30
|
-
B.urls.
|
31
|
-
C.urls.
|
29
|
+
A.urls.should == ["www.google.com"]
|
30
|
+
B.urls.should == Array.new
|
31
|
+
C.urls.should == Array.new
|
32
32
|
|
33
|
-
A.name.
|
34
|
-
B.name.
|
35
|
-
C.name.
|
33
|
+
A.name.should ==({:first => 'jon', :last => 'smith'})
|
34
|
+
B.name.should == Hash.new
|
35
|
+
C.name.should == Hash.new
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "descendents can update their own container properties" do
|
@@ -47,84 +47,84 @@ describe "container types: typical" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "works" do
|
50
|
-
B.urls.
|
51
|
-
C.urls.
|
50
|
+
B.urls.should == ["www.bing.com", "www.example.com"]
|
51
|
+
C.urls.should == ["c.homepage.org", "example.org"]
|
52
52
|
|
53
|
-
B.name.
|
54
|
-
C.name.
|
53
|
+
B.name.should ==({:first => 'charlie'})
|
54
|
+
C.name.should ==({:first => 'tim', :last => 'emerson'})
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "manual override: allowing inheritance" do
|
59
59
|
it "accepts ':inherit' syntax" do
|
60
|
-
B.urls(:inherit).
|
61
|
-
C.urls(:inherit).
|
60
|
+
B.urls(:inherit).should == ["www.google.com"]
|
61
|
+
C.urls(:inherit).should == ["www.google.com"]
|
62
62
|
|
63
|
-
B.name(:inherit).
|
64
|
-
C.name(:inherit).
|
63
|
+
B.name(:inherit).should ==({:first => 'jon', :last => 'smith'})
|
64
|
+
C.name(:inherit).should ==({:first => 'jon', :last => 'smith'})
|
65
65
|
end
|
66
66
|
|
67
67
|
it "accepts ':inherit => <val>' syntax" do
|
68
|
-
B.urls(:inherit => 0).
|
69
|
-
B.urls(:inherit => false).
|
70
|
-
B.urls(:inherit => nil).
|
71
|
-
B.urls(:inherit => 1).
|
72
|
-
B.urls(:inherit => true).
|
73
|
-
B.urls(:inherit => -1).
|
74
|
-
|
75
|
-
C.urls(:inherit => 0).
|
76
|
-
C.urls(:inherit => false).
|
77
|
-
C.urls(:inherit => nil).
|
78
|
-
C.urls(:inherit => 1).
|
79
|
-
C.urls(:inherit => 2).
|
80
|
-
C.urls(:inherit => -1).
|
81
|
-
C.urls(:inherit => true).
|
68
|
+
B.urls(:inherit => 0).should == []
|
69
|
+
B.urls(:inherit => false).should == []
|
70
|
+
B.urls(:inherit => nil).should == []
|
71
|
+
B.urls(:inherit => 1).should == ["www.google.com"]
|
72
|
+
B.urls(:inherit => true).should == ["www.google.com"]
|
73
|
+
B.urls(:inherit => -1).should == ["www.google.com"]
|
74
|
+
|
75
|
+
C.urls(:inherit => 0).should == []
|
76
|
+
C.urls(:inherit => false).should == []
|
77
|
+
C.urls(:inherit => nil).should == []
|
78
|
+
C.urls(:inherit => 1).should == []
|
79
|
+
C.urls(:inherit => 2).should == ["www.google.com"]
|
80
|
+
C.urls(:inherit => -1).should == ["www.google.com"]
|
81
|
+
C.urls(:inherit => true).should == ["www.google.com"]
|
82
82
|
end
|
83
83
|
|
84
84
|
it "accepts ':inherit, <val>' syntax" do
|
85
|
-
B.name(:inherit, 0).
|
86
|
-
B.name(:inherit, false).
|
87
|
-
B.name(:inherit, nil).
|
88
|
-
B.name(:inherit, 1).
|
89
|
-
B.name(:inherit, true).
|
90
|
-
B.name(:inherit, -1).
|
91
|
-
|
92
|
-
C.name(:inherit, 0).
|
93
|
-
C.name(:inherit, false).
|
94
|
-
C.name(:inherit, nil).
|
95
|
-
C.name(:inherit, 1).
|
96
|
-
C.name(:inherit, 2).
|
97
|
-
C.name(:inherit, true).
|
98
|
-
C.name(:inherit, -1).
|
85
|
+
B.name(:inherit, 0).should == Hash.new
|
86
|
+
B.name(:inherit, false).should == Hash.new
|
87
|
+
B.name(:inherit, nil).should == Hash.new
|
88
|
+
B.name(:inherit, 1).should ==({:first => 'jon', :last => 'smith'})
|
89
|
+
B.name(:inherit, true).should ==({:first => 'jon', :last => 'smith'})
|
90
|
+
B.name(:inherit, -1).should ==({:first => 'jon', :last => 'smith'})
|
91
|
+
|
92
|
+
C.name(:inherit, 0).should == Hash.new
|
93
|
+
C.name(:inherit, false).should == Hash.new
|
94
|
+
C.name(:inherit, nil).should == Hash.new
|
95
|
+
C.name(:inherit, 1).should == Hash.new
|
96
|
+
C.name(:inherit, 2).should ==({:first => 'jon', :last => 'smith'})
|
97
|
+
C.name(:inherit, true).should ==({:first => 'jon', :last => 'smith'})
|
98
|
+
C.name(:inherit, -1).should ==({:first => 'jon', :last => 'smith'})
|
99
99
|
end
|
100
100
|
|
101
101
|
describe "manual override has no effect on non-blank container properties" do
|
102
102
|
it "works" do
|
103
103
|
C.urls << "www.yahoo.com"
|
104
104
|
|
105
|
-
A.urls_is_blank?.
|
106
|
-
B.urls_is_blank?.
|
107
|
-
C.urls_is_blank?.
|
108
|
-
|
109
|
-
A.urls.
|
110
|
-
A.urls(:inherit).
|
111
|
-
A.urls(:inherit => false).
|
112
|
-
A.urls(:inherit => nil).
|
113
|
-
A.urls(:inherit => 0).
|
114
|
-
A.urls(:inherit => 1).
|
115
|
-
A.urls(:inherit => 2).
|
116
|
-
A.urls(:inherit => -1).
|
117
|
-
A.urls(:inherit => true).
|
118
|
-
|
119
|
-
C.urls.
|
120
|
-
C.urls(:inherit).
|
121
|
-
C.urls(:inherit, false).
|
122
|
-
C.urls(:inherit, nil).
|
123
|
-
C.urls(:inherit, 0).
|
124
|
-
C.urls(:inherit, 1).
|
125
|
-
C.urls(:inherit, 2).
|
126
|
-
C.urls(:inherit, -1).
|
127
|
-
C.urls(:inherit, true).
|
105
|
+
A.urls_is_blank?.should == false
|
106
|
+
B.urls_is_blank?.should == true
|
107
|
+
C.urls_is_blank?.should == false
|
108
|
+
|
109
|
+
A.urls.should == ["www.google.com"]
|
110
|
+
A.urls(:inherit).should == ["www.google.com"]
|
111
|
+
A.urls(:inherit => false).should == ["www.google.com"]
|
112
|
+
A.urls(:inherit => nil).should == ["www.google.com"]
|
113
|
+
A.urls(:inherit => 0).should == ["www.google.com"]
|
114
|
+
A.urls(:inherit => 1).should == ["www.google.com"]
|
115
|
+
A.urls(:inherit => 2).should == ["www.google.com"]
|
116
|
+
A.urls(:inherit => -1).should == ["www.google.com"]
|
117
|
+
A.urls(:inherit => true).should == ["www.google.com"]
|
118
|
+
|
119
|
+
C.urls.should == ["www.yahoo.com"]
|
120
|
+
C.urls(:inherit).should == ["www.yahoo.com"]
|
121
|
+
C.urls(:inherit, false).should == ["www.yahoo.com"]
|
122
|
+
C.urls(:inherit, nil).should == ["www.yahoo.com"]
|
123
|
+
C.urls(:inherit, 0).should == ["www.yahoo.com"]
|
124
|
+
C.urls(:inherit, 1).should == ["www.yahoo.com"]
|
125
|
+
C.urls(:inherit, 2).should == ["www.yahoo.com"]
|
126
|
+
C.urls(:inherit, -1).should == ["www.yahoo.com"]
|
127
|
+
C.urls(:inherit, true).should == ["www.yahoo.com"]
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
@@ -149,14 +149,14 @@ describe "container types: property-wide inheritance" do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
it "inherits by default" do
|
152
|
-
@props[:urls][:inherit].
|
153
|
-
@props[:name][:inherit].
|
152
|
+
@props[:urls][:inherit].should == true
|
153
|
+
@props[:name][:inherit].should == true
|
154
154
|
|
155
|
-
B.urls.
|
156
|
-
C.urls.
|
155
|
+
B.urls.should == ["www.google.com"]
|
156
|
+
C.urls.should == ["www.google.com"]
|
157
157
|
|
158
|
-
B.name.
|
159
|
-
C.name.
|
158
|
+
B.name.should ==({:first => 'jon', :last => 'smith'})
|
159
|
+
C.name.should ==({:first => 'jon', :last => 'smith'})
|
160
160
|
end
|
161
161
|
|
162
162
|
describe "a descendent updates a container property" do
|
@@ -165,37 +165,37 @@ describe "container types: property-wide inheritance" do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "cascades down its descendents" do
|
168
|
-
C.urls.
|
168
|
+
C.urls.should == ["www.bing.com"]
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
describe "overriding the inheritance effect" do
|
173
173
|
it "accepts ':inherit => <val>' syntax" do
|
174
|
-
B.urls.
|
175
|
-
C.urls.
|
174
|
+
B.urls.should == ["www.google.com"]
|
175
|
+
C.urls.should == ["www.google.com"]
|
176
176
|
|
177
|
-
B.urls(:inherit => false).
|
178
|
-
C.urls(:inherit => false).
|
177
|
+
B.urls(:inherit => false).should == []
|
178
|
+
C.urls(:inherit => false).should == []
|
179
179
|
|
180
|
-
B.urls(:inherit => 0).
|
181
|
-
C.urls(:inherit => 0).
|
180
|
+
B.urls(:inherit => 0).should == []
|
181
|
+
C.urls(:inherit => 0).should == []
|
182
182
|
|
183
|
-
B.urls(:inherit => 1).
|
184
|
-
C.urls(:inherit => 1).
|
183
|
+
B.urls(:inherit => 1).should == ["www.google.com"]
|
184
|
+
C.urls(:inherit => 1).should == []
|
185
185
|
end
|
186
186
|
|
187
187
|
it "accepts ':inherit, <val>' syntax" do
|
188
|
-
B.urls.
|
189
|
-
C.urls.
|
188
|
+
B.urls.should == ["www.google.com"]
|
189
|
+
C.urls.should == ["www.google.com"]
|
190
190
|
|
191
|
-
B.urls(:inherit, false).
|
192
|
-
C.urls(:inherit, false).
|
191
|
+
B.urls(:inherit, false).should == []
|
192
|
+
C.urls(:inherit, false).should == []
|
193
193
|
|
194
|
-
B.urls(:inherit, 0).
|
195
|
-
C.urls(:inherit, 0).
|
194
|
+
B.urls(:inherit, 0).should == []
|
195
|
+
C.urls(:inherit, 0).should == []
|
196
196
|
|
197
|
-
B.urls(:inherit, 1).
|
198
|
-
C.urls(:inherit, 1).
|
197
|
+
B.urls(:inherit, 1).should == ["www.google.com"]
|
198
|
+
C.urls(:inherit, 1).should == []
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
data/spec/basics/inherit_spec.rb
CHANGED
@@ -37,56 +37,56 @@ describe "inherit" do
|
|
37
37
|
|
38
38
|
describe "descendents" do
|
39
39
|
it "inherits symbols strings, fixnums, floats, and bools (by default)" do
|
40
|
-
@props[:location][:inherit].
|
41
|
-
@props[:weather][:inherit].
|
42
|
-
@props[:num][:inherit].
|
43
|
-
@props[:score][:inherit].
|
44
|
-
@props[:available][:inherit].
|
40
|
+
@props[:location][:inherit].should == true
|
41
|
+
@props[:weather][:inherit].should == true
|
42
|
+
@props[:num][:inherit].should == true
|
43
|
+
@props[:score][:inherit].should == true
|
44
|
+
@props[:available][:inherit].should == true
|
45
45
|
|
46
|
-
B.location.
|
47
|
-
C.location.
|
46
|
+
B.location.should == "south side"
|
47
|
+
C.location.should == "south side"
|
48
48
|
|
49
|
-
B.weather.
|
50
|
-
C.weather.
|
49
|
+
B.weather.should == :sunny
|
50
|
+
C.weather.should == :sunny
|
51
51
|
|
52
|
-
B.num.
|
53
|
-
C.num.
|
52
|
+
B.num.should == 12
|
53
|
+
C.num.should == 12
|
54
54
|
|
55
|
-
B.score.
|
56
|
-
C.score.
|
55
|
+
B.score.should == 32.18
|
56
|
+
C.score.should == 32.18
|
57
57
|
|
58
|
-
B.available.
|
59
|
-
C.available.
|
58
|
+
B.available.should == false
|
59
|
+
C.available.should == false
|
60
60
|
end
|
61
61
|
|
62
62
|
it "doesn't inherit containers like hashes, arrays, and sets (by default)" do
|
63
|
-
@props[:name][:inherit].
|
64
|
-
@props[:groceries][:inherit].
|
63
|
+
@props[:name][:inherit].should == false
|
64
|
+
@props[:groceries][:inherit].should == false
|
65
65
|
|
66
|
-
B.name.
|
67
|
-
C.name.
|
66
|
+
B.name.should == Hash.new
|
67
|
+
C.name.should == Hash.new
|
68
68
|
|
69
|
-
B.groceries.
|
70
|
-
C.groceries.
|
69
|
+
B.groceries.should == Array.new
|
70
|
+
C.groceries.should == Array.new
|
71
71
|
|
72
|
-
B.ingredients.
|
73
|
-
C.ingredients.
|
72
|
+
B.ingredients.should == Set.new
|
73
|
+
C.ingredients.should == Set.new
|
74
74
|
end
|
75
75
|
|
76
76
|
it "inherits properties of type ':Proc'" do
|
77
|
-
@props[:mood][:inherit].
|
77
|
+
@props[:mood][:inherit].should == true
|
78
78
|
|
79
79
|
A.weather = :sunny
|
80
80
|
B.weather = :rainy
|
81
81
|
|
82
|
-
C.weather.
|
82
|
+
C.weather.should == :rainy
|
83
83
|
|
84
|
-
A.mood.
|
85
|
-
B.mood.
|
86
|
-
C.mood.
|
84
|
+
A.mood.should == "content"
|
85
|
+
B.mood.should == "depressed"
|
86
|
+
C.mood.should == "depressed"
|
87
87
|
|
88
88
|
C.weather = :sunny
|
89
|
-
C.mood.
|
89
|
+
C.mood.should == "content"
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -112,124 +112,124 @@ describe "inherit" do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "allows 'false', 'nil' and '0' to force no inheritance" do
|
115
|
-
B.location(false).
|
116
|
-
C.location(false).
|
115
|
+
B.location(false).should == ""
|
116
|
+
C.location(false).should == ""
|
117
117
|
|
118
|
-
B.score(nil).
|
119
|
-
C.score(nil).
|
118
|
+
B.score(nil).should == nil
|
119
|
+
C.score(nil).should == nil
|
120
120
|
|
121
|
-
B.weather(0).
|
122
|
-
C.weather(0).
|
121
|
+
B.weather(0).should == nil
|
122
|
+
C.weather(0).should == nil
|
123
123
|
end
|
124
124
|
|
125
125
|
it "allows 'true', '-1' to force full, inifinte max inheritance" do
|
126
|
-
B.num(true).
|
127
|
-
C.num(true).
|
126
|
+
B.num(true).should == 12
|
127
|
+
C.num(true).should == 12
|
128
128
|
|
129
|
-
B.groceries(-1).
|
130
|
-
C.groceries(-1).
|
129
|
+
B.groceries(-1).should == [:ice, :lemons, :splenda]
|
130
|
+
C.groceries(-1).should == [:ice, :lemons, :splenda]
|
131
131
|
end
|
132
132
|
|
133
133
|
it "allows '<fixnum>' value to indicate max inheritance age" do
|
134
|
-
B.score(0).
|
135
|
-
B.score(1).
|
136
|
-
B.score(2).
|
137
|
-
C.score(1).
|
138
|
-
C.score(2).
|
139
|
-
|
140
|
-
B.name(0).
|
141
|
-
B.name(1).
|
142
|
-
C.name(0).
|
143
|
-
C.name(1).
|
144
|
-
C.name(2).
|
134
|
+
B.score(0).should == nil
|
135
|
+
B.score(1).should == 32.18
|
136
|
+
B.score(2).should == 32.18
|
137
|
+
C.score(1).should == nil
|
138
|
+
C.score(2).should == 32.18
|
139
|
+
|
140
|
+
B.name(0).should == Hash.new
|
141
|
+
B.name(1).should ==({:first => 'jon', :last => 'smith'})
|
142
|
+
C.name(0).should == Hash.new
|
143
|
+
C.name(1).should == Hash.new
|
144
|
+
C.name(2).should ==({:first => 'jon', :last => 'smith'})
|
145
145
|
end
|
146
146
|
|
147
147
|
it "allows ':inherit => false' and ':inherit => nil' syntax" do
|
148
|
-
B.location(:inherit => false).
|
148
|
+
B.location(:inherit => false).should == ""
|
149
149
|
c_location = C.location :inherit => false
|
150
|
-
c_location.
|
150
|
+
c_location.should == ""
|
151
151
|
|
152
|
-
B.weather(:inherit => nil).
|
152
|
+
B.weather(:inherit => nil).should == nil
|
153
153
|
c_weather = C.weather :inherit => nil
|
154
|
-
c_weather.
|
154
|
+
c_weather.should == nil
|
155
155
|
end
|
156
156
|
|
157
157
|
it "allows ':inhert, false' and ':inherit, nil' syntax" do
|
158
|
-
B.num(:inherit, false).
|
158
|
+
B.num(:inherit, false).should == nil
|
159
159
|
c_num = C.num :inherit, false
|
160
|
-
c_num.
|
160
|
+
c_num.should == nil
|
161
161
|
|
162
|
-
B.score(:inherit, nil).
|
162
|
+
B.score(:inherit, nil).should == nil
|
163
163
|
c_score = C.score :inherit, nil
|
164
|
-
c_score.
|
164
|
+
c_score.should == nil
|
165
165
|
end
|
166
166
|
|
167
167
|
it "allows ':inherit => true' and ':inherit => -1' syntax" do
|
168
|
-
B.name(:inherit => true).
|
168
|
+
B.name(:inherit => true).should ==({:first => 'jon', :last => 'smith'})
|
169
169
|
c_name = C.name :inherit => true
|
170
|
-
c_name.
|
170
|
+
c_name.should ==({:first => 'jon', :last => 'smith'})
|
171
171
|
|
172
|
-
B.groceries(:inherit => -1).
|
172
|
+
B.groceries(:inherit => -1).should == [:ice, :lemons, :splenda]
|
173
173
|
c_groceries = C.groceries :inherit => -1
|
174
|
-
c_groceries.
|
174
|
+
c_groceries.should == [:ice, :lemons, :splenda]
|
175
175
|
end
|
176
176
|
|
177
177
|
it "allows ':inherit, true' and ':inherit, -1' syntax" do
|
178
|
-
B.ingredients(:inherit, true).
|
178
|
+
B.ingredients(:inherit, true).should == Set.new([:sugar, :butter, :flour, :eggs])
|
179
179
|
c_ingredients = C.ingredients :inherit, true
|
180
|
-
c_ingredients.
|
180
|
+
c_ingredients.should == Set.new([:sugar, :butter, :flour, :eggs])
|
181
181
|
|
182
|
-
B.name(:inherit, -1).
|
182
|
+
B.name(:inherit, -1).should ==({:first => 'jon', :last => 'smith'})
|
183
183
|
c_name = C.name :inherit, -1
|
184
|
-
c_name.
|
184
|
+
c_name.should ==({:first => 'jon', :last => 'smith'})
|
185
185
|
end
|
186
186
|
|
187
187
|
it "allows ':inherit => <n>' (n: fixnum) syntax" do
|
188
|
-
B.location(:inherit => 0).
|
189
|
-
B.location(:inherit => 1).
|
188
|
+
B.location(:inherit => 0).should == ''
|
189
|
+
B.location(:inherit => 1).should == "south side"
|
190
190
|
|
191
191
|
c_loc_0 = C.location :inherit => 0
|
192
192
|
c_loc_1 = C.location :inherit => 1
|
193
193
|
c_loc_2 = C.location :inherit => 2
|
194
194
|
|
195
|
-
c_loc_0.
|
196
|
-
c_loc_1.
|
197
|
-
c_loc_2.
|
195
|
+
c_loc_0.should == ''
|
196
|
+
c_loc_1.should == ''
|
197
|
+
c_loc_2.should == "south side"
|
198
198
|
|
199
|
-
B.groceries(:inherit => 0).
|
200
|
-
B.groceries(:inherit => 1).
|
199
|
+
B.groceries(:inherit => 0).should == []
|
200
|
+
B.groceries(:inherit => 1).should == [:ice, :lemons, :splenda]
|
201
201
|
|
202
202
|
c_groc_0 = C.groceries :inherit => 0
|
203
203
|
c_groc_1 = C.groceries :inherit => 1
|
204
204
|
c_groc_2 = C.groceries :inherit => 2
|
205
205
|
|
206
|
-
c_groc_0.
|
207
|
-
c_groc_1.
|
208
|
-
c_groc_2.
|
206
|
+
c_groc_0.should == []
|
207
|
+
c_groc_1.should == []
|
208
|
+
c_groc_2.should == [:ice, :lemons, :splenda]
|
209
209
|
end
|
210
210
|
|
211
211
|
it "allows ':inherit, <n>' (n: fixnum) syntax" do
|
212
|
-
B.score(:inherit, 0).
|
213
|
-
B.score(:inherit, 1).
|
212
|
+
B.score(:inherit, 0).should == nil
|
213
|
+
B.score(:inherit, 1).should == 32.18
|
214
214
|
|
215
215
|
c_score_0 = C.score :inherit, 0
|
216
216
|
c_score_1 = C.score :inherit, 1
|
217
217
|
c_score_2 = C.score :inherit, 2
|
218
218
|
|
219
|
-
c_score_0.
|
220
|
-
c_score_1.
|
221
|
-
c_score_2.
|
219
|
+
c_score_0.should == nil
|
220
|
+
c_score_1.should == nil
|
221
|
+
c_score_2.should == 32.18
|
222
222
|
|
223
|
-
B.ingredients(:inherit, 0).
|
224
|
-
B.ingredients(:inherit, 1).
|
223
|
+
B.ingredients(:inherit, 0).should == Set.new([])
|
224
|
+
B.ingredients(:inherit, 1).should == Set.new([:sugar, :butter, :flour, :eggs])
|
225
225
|
|
226
226
|
c_ingr_0 = C.ingredients :inherit, 0
|
227
227
|
c_ingr_1 = C.ingredients :inherit, 1
|
228
228
|
c_ingr_2 = C.ingredients :inherit, 2
|
229
229
|
|
230
|
-
c_ingr_0.
|
231
|
-
c_ingr_1.
|
232
|
-
c_ingr_2.
|
230
|
+
c_ingr_0.should == Set.new([])
|
231
|
+
c_ingr_1.should == Set.new([])
|
232
|
+
c_ingr_2.should == Set.new([:sugar, :butter, :flour, :eggs])
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -252,85 +252,85 @@ describe "inherit" do
|
|
252
252
|
end
|
253
253
|
|
254
254
|
it "all should not inherit" do
|
255
|
-
@props[:location][:inherit].
|
256
|
-
@props[:score][:inherit].
|
257
|
-
@props[:num][:inherit].
|
258
|
-
@props[:weather][:inherit].
|
259
|
-
@props[:available][:inherit].
|
260
|
-
@props[:mood][:inherit].
|
261
|
-
@props[:color][:inherit].
|
262
|
-
@props[:groceries][:inherit].
|
263
|
-
@props[:ingredients][:inherit].
|
264
|
-
|
265
|
-
A.location.
|
266
|
-
B.location.
|
267
|
-
C.location.
|
268
|
-
|
269
|
-
A.score.
|
270
|
-
B.score.
|
271
|
-
C.score.
|
272
|
-
|
273
|
-
A.num.
|
274
|
-
B.num.
|
275
|
-
C.num.
|
276
|
-
|
277
|
-
A.weather.
|
278
|
-
B.weather.
|
279
|
-
C.weather.
|
280
|
-
|
281
|
-
A.available.
|
282
|
-
B.available.
|
283
|
-
C.available.
|
284
|
-
|
285
|
-
A.mood.
|
286
|
-
B.mood.
|
287
|
-
C.mood.
|
288
|
-
|
289
|
-
A.color.
|
290
|
-
B.color.
|
291
|
-
C.color.
|
292
|
-
|
293
|
-
A.name.
|
294
|
-
B.name.
|
295
|
-
C.name.
|
296
|
-
|
297
|
-
A.groceries.
|
298
|
-
B.groceries.
|
299
|
-
C.groceries.
|
300
|
-
|
301
|
-
A.ingredients.
|
302
|
-
B.ingredients.
|
303
|
-
C.ingredients.
|
255
|
+
@props[:location][:inherit].should == false
|
256
|
+
@props[:score][:inherit].should == false
|
257
|
+
@props[:num][:inherit].should == false
|
258
|
+
@props[:weather][:inherit].should == false
|
259
|
+
@props[:available][:inherit].should == false
|
260
|
+
@props[:mood][:inherit].should == false
|
261
|
+
@props[:color][:inherit].should == false
|
262
|
+
@props[:groceries][:inherit].should == false
|
263
|
+
@props[:ingredients][:inherit].should == false
|
264
|
+
|
265
|
+
A.location.should == "south side"
|
266
|
+
B.location.should == ''
|
267
|
+
C.location.should == ''
|
268
|
+
|
269
|
+
A.score.should == 32.18
|
270
|
+
B.score.should == nil
|
271
|
+
C.score.should == nil
|
272
|
+
|
273
|
+
A.num.should == 12
|
274
|
+
B.num.should == nil
|
275
|
+
C.num.should == nil
|
276
|
+
|
277
|
+
A.weather.should == :sunny
|
278
|
+
B.weather.should == nil
|
279
|
+
C.weather.should == nil
|
280
|
+
|
281
|
+
A.available.should == false
|
282
|
+
B.available.should == nil
|
283
|
+
C.available.should == nil
|
284
|
+
|
285
|
+
A.mood.should == "content"
|
286
|
+
B.mood.should == "depressed"
|
287
|
+
C.mood.should == "depressed"
|
288
|
+
|
289
|
+
A.color.should == "rosy"
|
290
|
+
B.color.should == "B: blue"
|
291
|
+
C.color.should == "blue"
|
292
|
+
|
293
|
+
A.name.should ==({:first => 'jon', :last => 'smith'})
|
294
|
+
B.name.should == Hash.new
|
295
|
+
C.name.should == Hash.new
|
296
|
+
|
297
|
+
A.groceries.should == [:ice, :lemons, :splenda]
|
298
|
+
B.groceries.should == Array.new
|
299
|
+
C.groceries.should == Array.new
|
300
|
+
|
301
|
+
A.ingredients.should == Set.new([:sugar, :butter, :flour, :eggs])
|
302
|
+
B.ingredients.should == Set.new
|
303
|
+
C.ingredients.should == Set.new
|
304
304
|
end
|
305
305
|
|
306
306
|
describe "manual inheritance age override" do
|
307
307
|
it "allows 'true' and '-1' syntax" do
|
308
|
-
B.location(true).
|
309
|
-
C.location(true).
|
308
|
+
B.location(true).should == "south side"
|
309
|
+
C.location(true).should == "south side"
|
310
310
|
|
311
|
-
B.score(-1).
|
312
|
-
C.score(-1).
|
311
|
+
B.score(-1).should == 32.18
|
312
|
+
C.score(-1).should == 32.18
|
313
313
|
|
314
|
-
B.ingredients(true).
|
315
|
-
C.ingredients(true).
|
314
|
+
B.ingredients(true).should == Set.new([:sugar, :butter, :flour, :eggs])
|
315
|
+
C.ingredients(true).should == Set.new([:sugar, :butter, :flour, :eggs])
|
316
316
|
end
|
317
317
|
|
318
318
|
it "allows <fixnum> (n > 0) syntax to indicate max inheritance age" do
|
319
|
-
B.weather(0).
|
320
|
-
B.weather(1).
|
321
|
-
B.weather(2).
|
322
|
-
C.weather(0).
|
323
|
-
C.weather(1).
|
324
|
-
C.weather(2).
|
325
|
-
C.weather(3).
|
326
|
-
|
327
|
-
B.groceries(0).
|
328
|
-
B.groceries(1).
|
329
|
-
B.groceries(2).
|
330
|
-
C.groceries(0).
|
331
|
-
C.groceries(1).
|
332
|
-
C.groceries(2).
|
333
|
-
C.groceries(3).
|
319
|
+
B.weather(0).should == nil
|
320
|
+
B.weather(1).should == :sunny
|
321
|
+
B.weather(2).should == :sunny
|
322
|
+
C.weather(0).should == nil
|
323
|
+
C.weather(1).should == nil
|
324
|
+
C.weather(2).should == :sunny
|
325
|
+
C.weather(3).should == :sunny
|
326
|
+
|
327
|
+
B.groceries(0).should == Array.new
|
328
|
+
B.groceries(1).should == [:ice, :lemons, :splenda]
|
329
|
+
B.groceries(2).should == [:ice, :lemons, :splenda]
|
330
|
+
C.groceries(0).should == Array.new
|
331
|
+
C.groceries(1).should == Array.new
|
332
|
+
C.groceries(2).should == Array.new [:ice, :lemons, :splenda]
|
333
|
+
C.groceries(3).should == Array.new [:ice, :lemons, :splenda]
|
334
334
|
end
|
335
335
|
end
|
336
336
|
end
|