phenomenal 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +27 -0
- data/README +3 -0
- data/Rakefile +11 -0
- data/lib/phenomenal.rb +24 -0
- data/lib/phenomenal/adaptation.rb +79 -0
- data/lib/phenomenal/conflict_policies.rb +20 -0
- data/lib/phenomenal/context.rb +269 -0
- data/lib/phenomenal/dsl.rb +119 -0
- data/lib/phenomenal/feature.rb +8 -0
- data/lib/phenomenal/logger.rb +34 -0
- data/lib/phenomenal/manager.rb +317 -0
- data/lib/phenomenal/proc.rb +34 -0
- data/lib/phenomenal/relationships/context_relationships.rb +22 -0
- data/lib/phenomenal/relationships/dsl.rb +18 -0
- data/lib/phenomenal/relationships/feature_relationships.rb +42 -0
- data/lib/phenomenal/relationships/implication.rb +35 -0
- data/lib/phenomenal/relationships/relationship.rb +42 -0
- data/lib/phenomenal/relationships/relationships_manager.rb +63 -0
- data/lib/phenomenal/relationships/relationships_store.rb +73 -0
- data/lib/phenomenal/relationships/requirement.rb +26 -0
- data/lib/phenomenal/relationships/suggestion.rb +41 -0
- data/lib/phenomenal/version.rb +3 -0
- data/spec/adaptation_spec.rb +64 -0
- data/spec/behavior/adaptation_spec.rb +5 -0
- data/spec/behavior/combined_contexts_spec.rb +5 -0
- data/spec/behavior/composition_spec.rb +5 -0
- data/spec/behavior/conflict_policy_spec.rb +5 -0
- data/spec/behavior/open_context.rb +5 -0
- data/spec/behavior/relationships_spec.rb +249 -0
- data/spec/context_spec.rb +268 -0
- data/spec/dsl_spec.rb +181 -0
- data/spec/feature_spec.rb +5 -0
- data/spec/manager_spec.rb +84 -0
- data/spec/proc_spec.rb +20 -0
- data/spec/relationships/context_relationships_spec.rb +13 -0
- data/spec/relationships/dsl_spec.rb +13 -0
- data/spec/relationships/feature_relationships_spec.rb +13 -0
- data/spec/relationships/relationship_spec.rb +31 -0
- data/spec/relationships/relationships_manager_spec.rb +15 -0
- data/spec/relationships/relationships_store_spec.rb +19 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/test_classes.rb +111 -0
- metadata +124 -0
@@ -0,0 +1,268 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Phenomenal::Context do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@context = Phenomenal::Context.new(:test)
|
7
|
+
@context2 = Phenomenal::Context.new(:test2)
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
force_forget_context(@context)
|
12
|
+
force_forget_context(@context2)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should exist" do
|
16
|
+
@context.should be_an_instance_of(Phenomenal::Context)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should accept adaptations" do
|
20
|
+
@context.should respond_to :add_adaptation
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept removing of adaptations" do
|
24
|
+
@context.should respond_to :remove_adaptation
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#name" do
|
28
|
+
it "should have a name" do
|
29
|
+
@context.should respond_to :name
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should keep it's initial name" do
|
33
|
+
@context.name.should == :test
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be anonymous if the name wasn't set" do
|
37
|
+
Phenomenal::Context.new.name.should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be anonymous if it is the default context" do
|
41
|
+
Phenomenal::Manager.instance.default_context.name.should be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".create" do
|
46
|
+
pending "TODO"
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#forget" do
|
50
|
+
pending "TODO"
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#add_adaptation" do
|
54
|
+
pending "TODO"
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#remove_adaptation" do
|
58
|
+
pending "TODO"
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#context" do
|
62
|
+
pending "TODO"
|
63
|
+
|
64
|
+
describe "#phen_context" do
|
65
|
+
it "should be an alias of #context" do
|
66
|
+
Phenomenal::Context.instance_method(:context).should==Phenomenal::Context.instance_method(:phen_context)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#feature" do
|
72
|
+
pending "TODO"
|
73
|
+
|
74
|
+
describe "#phen_feature" do
|
75
|
+
it "should be an alias of #feature" do
|
76
|
+
Phenomenal::Context.instance_method(:feature).should==Phenomenal::Context.instance_method(:phen_feature)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#add_adaptations" do
|
82
|
+
pending "TODO"
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#adapatations_for" do
|
86
|
+
pending "TODO"
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#adapt" do
|
90
|
+
pending "TODO"
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#adapt_klass" do
|
94
|
+
pending "TODO"
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe "(de)activation of contexts" do
|
99
|
+
it "should initially not be active" do
|
100
|
+
@context.active?.should be_false
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#activate" do
|
104
|
+
it "should be activatable" do
|
105
|
+
@context.should respond_to :activate
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should activate the context" do
|
109
|
+
@context.activate
|
110
|
+
@context.active?.should be_true
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should increment activation count" do
|
114
|
+
@context.activate
|
115
|
+
@context.activation_count.should == 1
|
116
|
+
@context.activate
|
117
|
+
@context.activation_count.should == 2
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should reset activation age" do
|
121
|
+
@context.activate
|
122
|
+
@context.age.should == 0
|
123
|
+
@context2.activate
|
124
|
+
@context.age.should == 1
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return the context on activation" do
|
128
|
+
@context.should be @context.activate
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#deactivate" do
|
133
|
+
it "should be deactivatable" do
|
134
|
+
@context.should respond_to :deactivate
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return the context on deactivation" do
|
138
|
+
@context.should be @context.deactivate
|
139
|
+
end
|
140
|
+
it "should be inactive after deactivation" do
|
141
|
+
@context.activate
|
142
|
+
@context.deactivate
|
143
|
+
@context.active?.should be_false
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "Redundant (de)activations " do
|
148
|
+
before :each do
|
149
|
+
10.times { @context.activate }
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should stay active with fewer deactivations than activations" do
|
153
|
+
9.times { @context.deactivate }
|
154
|
+
@context.active?.should be true
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should became inactive with same deactivations than activations" do
|
158
|
+
10.times { @context.deactivate }
|
159
|
+
@context.active?.should be false
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should stay inactive with more deactivations than activations" do
|
163
|
+
15.times { @context.deactivate }
|
164
|
+
@context.active?.should be false
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should not accumulate once the context is inactive" do
|
168
|
+
15.times { @context.deactivate }
|
169
|
+
@context.activate
|
170
|
+
@context.active?.should be true
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#just_activated?" do
|
175
|
+
it "should be false if the context is inactive" do
|
176
|
+
@context.just_activated?.should be_false
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should be true if the context has becamed active at the very prior activation" do
|
180
|
+
@context.activate
|
181
|
+
@context.just_activated?.should be_true
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should be false again for the following activations" do
|
185
|
+
@context.activate.activate
|
186
|
+
@context.just_activated?.should be_false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#anonymous?" do
|
192
|
+
after do
|
193
|
+
force_forget_context(@context3)
|
194
|
+
end
|
195
|
+
it "should be true when the context has no name" do
|
196
|
+
@context3 = Phenomenal::Context.new
|
197
|
+
@context3.anonymous?.should be_true
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should be false when the context has a name" do
|
201
|
+
@context.anonymous?.should be_false
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be true for the default context" do
|
205
|
+
Phenomenal::Manager.instance.default_context.anonymous?.should be_true
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#information" do
|
210
|
+
it "should have all and only 6 defined fields " do
|
211
|
+
@context.information.should have(6).items
|
212
|
+
end
|
213
|
+
it "should have a matching :name field" do
|
214
|
+
@context.information[:name].should==:test
|
215
|
+
default = Phenomenal::Manager.instance.default_context
|
216
|
+
default.information[:name].should be_nil
|
217
|
+
end
|
218
|
+
it "should have a matching :adaptation field" do
|
219
|
+
@context.information[:adaptations].should==@context.adaptations
|
220
|
+
end
|
221
|
+
it "should have a matching :active field" do
|
222
|
+
@context.information[:active].should be_false
|
223
|
+
@context.activate
|
224
|
+
@context.information[:active].should be_true
|
225
|
+
end
|
226
|
+
it "should have a matching :age field" do
|
227
|
+
@context.activate
|
228
|
+
@context.information[:age].should==0
|
229
|
+
@context2.activate
|
230
|
+
@context.information[:age].should==1
|
231
|
+
@context2.information[:age].should==0
|
232
|
+
end
|
233
|
+
it "should have a matching :activation_count field" do
|
234
|
+
@context.information[:activation_count].should==0
|
235
|
+
@context.activate
|
236
|
+
@context.information[:activation_count].should==1
|
237
|
+
end
|
238
|
+
after do
|
239
|
+
force_forget_context(@feature)
|
240
|
+
end
|
241
|
+
it "should have a matching :type field" do
|
242
|
+
@context.information[:type].should=="Phenomenal::Context"
|
243
|
+
@feature = Phenomenal::Feature.new
|
244
|
+
@feature.information[:type].should=="Phenomenal::Feature"
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
end
|
249
|
+
describe "#parent_feature" do
|
250
|
+
it "should be the default feature parent for simple contexts" do
|
251
|
+
c = context :b
|
252
|
+
c.parent_feature.should be Phenomenal::Manager.instance.default_context
|
253
|
+
c.forget
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should be the closest feature for in-feature contexts" do
|
257
|
+
c=nil
|
258
|
+
f = feature :f do
|
259
|
+
c=context :c do
|
260
|
+
end
|
261
|
+
end
|
262
|
+
c.parent_feature.should be f
|
263
|
+
c.forget
|
264
|
+
f.forget
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
data/spec/dsl_spec.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Phenomenal::DSL do
|
4
|
+
|
5
|
+
describe "#phen_define_context" do
|
6
|
+
pending "TODO"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#phen_context" do
|
10
|
+
it "should exist in Kernel" do
|
11
|
+
Kernel.should respond_to :phen_context
|
12
|
+
end
|
13
|
+
|
14
|
+
pending "TODO"
|
15
|
+
|
16
|
+
describe "#context" do
|
17
|
+
it "should exist in Kernel" do
|
18
|
+
Kernel.should respond_to :context
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be an alias of phen_context" do
|
22
|
+
Kernel.method(:phen_context).should == Kernel.method(:context)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#phen_feature" do
|
28
|
+
it "should exist in Kernel" do
|
29
|
+
Kernel.should respond_to :phen_feature
|
30
|
+
end
|
31
|
+
|
32
|
+
pending "TODO"
|
33
|
+
|
34
|
+
describe "#feature" do
|
35
|
+
it "should exist in Kernel" do
|
36
|
+
Kernel.should respond_to :feature
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be an alias of phen_context" do
|
40
|
+
Kernel.method(:phen_feature).should == Kernel.method(:feature)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#phen_forget_context" do
|
46
|
+
it "should exist in Kernel" do
|
47
|
+
Kernel.should respond_to :phen_forget_context
|
48
|
+
end
|
49
|
+
|
50
|
+
pending "TODO"
|
51
|
+
end
|
52
|
+
describe "#phen_add_adaptation" do
|
53
|
+
it "should exist in Kernel" do
|
54
|
+
Kernel.should respond_to :phen_add_adaptation
|
55
|
+
end
|
56
|
+
|
57
|
+
pending "TODO"
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#phen_add_class_adaptation" do
|
61
|
+
it "should exist in Kernel" do
|
62
|
+
Kernel.should respond_to :phen_add_class_adaptation
|
63
|
+
end
|
64
|
+
|
65
|
+
pending "TODO"
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#phen_remove_adaptation" do
|
69
|
+
it "should exist in Kernel" do
|
70
|
+
Kernel.should respond_to :phen_remove_adaptation
|
71
|
+
end
|
72
|
+
|
73
|
+
pending "TODO"
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#phen_remove_class_adaptation" do
|
77
|
+
it "should exist in Kernel" do
|
78
|
+
Kernel.should respond_to :phen_remove_class_adaptation
|
79
|
+
end
|
80
|
+
|
81
|
+
pending "TODO"
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#phen_activate_context" do
|
85
|
+
it "should exist in Kernel" do
|
86
|
+
Kernel.should respond_to :phen_activate_context
|
87
|
+
end
|
88
|
+
|
89
|
+
pending "TODO"
|
90
|
+
|
91
|
+
describe "#activate_context" do
|
92
|
+
it "should exist in Kernel" do
|
93
|
+
Kernel.should respond_to :activate_context
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be an alias of phen_context" do
|
97
|
+
Kernel.method(:phen_activate_context).should == Kernel.method(:activate_context)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#phen_deactivate_context" do
|
103
|
+
it "should exist in Kernel" do
|
104
|
+
Kernel.should respond_to :phen_deactivate_context
|
105
|
+
end
|
106
|
+
|
107
|
+
pending "TODO"
|
108
|
+
|
109
|
+
describe "#deactivate_context" do
|
110
|
+
it "should exist in Kernel" do
|
111
|
+
Kernel.should respond_to :deactivate_context
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should be an alias of phen_context" do
|
115
|
+
Kernel.method(:phen_deactivate_context).should == Kernel.method(:deactivate_context)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#phen_context_active?" do
|
121
|
+
it "should exist in Kernel" do
|
122
|
+
Kernel.should respond_to :phen_context_active?
|
123
|
+
end
|
124
|
+
|
125
|
+
pending "TODO"
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#phen_context_information" do
|
129
|
+
it "should exist in Kernel" do
|
130
|
+
Kernel.should respond_to :phen_context_information
|
131
|
+
end
|
132
|
+
|
133
|
+
pending "TODO"
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#phen_default_context" do
|
137
|
+
it "should exist in Kernel" do
|
138
|
+
Kernel.should respond_to :phen_default_context
|
139
|
+
end
|
140
|
+
|
141
|
+
pending "TODO"
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#phen_defined_contexts" do
|
145
|
+
it "should exist in Kernel" do
|
146
|
+
Kernel.should respond_to :phen_defined_contexts
|
147
|
+
end
|
148
|
+
|
149
|
+
pending "TODO"
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#phen_proceed" do
|
153
|
+
it "should exist in Kernel" do
|
154
|
+
Kernel.should respond_to :phen_proceed
|
155
|
+
end
|
156
|
+
|
157
|
+
pending "TODO"
|
158
|
+
|
159
|
+
describe "#proceed" do
|
160
|
+
it "should exist in Kernel" do
|
161
|
+
Kernel.should respond_to :proceed
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should be an alias of phen_context" do
|
165
|
+
Kernel.method(:phen_proceed).should == Kernel.method(:proceed)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "#phen_change_conflict_policy" do
|
171
|
+
it "should exist in Kernel" do
|
172
|
+
Kernel.should respond_to :phen_change_conflict_policy
|
173
|
+
end
|
174
|
+
|
175
|
+
pending "TODO"
|
176
|
+
end
|
177
|
+
|
178
|
+
describe ".phen_alias" do
|
179
|
+
pending "TODO"
|
180
|
+
end
|
181
|
+
end
|