phenomenal 0.9.0 → 0.11.11.24.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/LICENSE +1 -1
  2. data/README +4 -3
  3. data/Rakefile +0 -3
  4. data/demo.rb +24 -0
  5. data/demo_age.rb +89 -0
  6. data/demo_dsl.rb +28 -0
  7. data/lib/phenomenal.rb +2 -15
  8. data/lib/phenomenal/adaptation.rb +12 -22
  9. data/lib/phenomenal/context.rb +134 -127
  10. data/lib/phenomenal/dsl.rb +14 -41
  11. data/lib/phenomenal/logger.rb +1 -0
  12. data/lib/phenomenal/manager.rb +35 -117
  13. data/phenomenal.gemspec +15 -0
  14. data/{spec → test}/test_classes.rb +0 -3
  15. data/test/test_cop_adaptation.rb +168 -0
  16. data/test/test_cop_composition.rb +84 -0
  17. data/test/test_cop_conflictpolicy.rb +177 -0
  18. data/test/test_cop_infrastructure.rb +129 -0
  19. data/test_declaration.rb +18 -0
  20. metadata +29 -70
  21. data/lib/phenomenal/feature.rb +0 -8
  22. data/lib/phenomenal/relationships/context_relationships.rb +0 -22
  23. data/lib/phenomenal/relationships/dsl.rb +0 -18
  24. data/lib/phenomenal/relationships/feature_relationships.rb +0 -42
  25. data/lib/phenomenal/relationships/implication.rb +0 -35
  26. data/lib/phenomenal/relationships/relationship.rb +0 -42
  27. data/lib/phenomenal/relationships/relationships_manager.rb +0 -63
  28. data/lib/phenomenal/relationships/relationships_store.rb +0 -73
  29. data/lib/phenomenal/relationships/requirement.rb +0 -26
  30. data/lib/phenomenal/relationships/suggestion.rb +0 -41
  31. data/lib/phenomenal/version.rb +0 -3
  32. data/spec/adaptation_spec.rb +0 -64
  33. data/spec/behavior/adaptation_spec.rb +0 -5
  34. data/spec/behavior/combined_contexts_spec.rb +0 -5
  35. data/spec/behavior/composition_spec.rb +0 -5
  36. data/spec/behavior/conflict_policy_spec.rb +0 -5
  37. data/spec/behavior/open_context.rb +0 -5
  38. data/spec/behavior/relationships_spec.rb +0 -249
  39. data/spec/context_spec.rb +0 -268
  40. data/spec/dsl_spec.rb +0 -181
  41. data/spec/feature_spec.rb +0 -5
  42. data/spec/manager_spec.rb +0 -84
  43. data/spec/proc_spec.rb +0 -20
  44. data/spec/relationships/context_relationships_spec.rb +0 -13
  45. data/spec/relationships/dsl_spec.rb +0 -13
  46. data/spec/relationships/feature_relationships_spec.rb +0 -13
  47. data/spec/relationships/relationship_spec.rb +0 -31
  48. data/spec/relationships/relationships_manager_spec.rb +0 -15
  49. data/spec/relationships/relationships_store_spec.rb +0 -19
  50. data/spec/spec_helper.rb +0 -18
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Simple adaptations" do
4
- pending "TODO"
5
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Combined contexts" do
4
- pending "TODO"
5
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Composition of adaptations" do
4
- pending "TODO"
5
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Conflict policies" do
4
- pending "TODO"
5
- end
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Open context facilities" do
4
- pending "TODO"
5
- end
@@ -1,249 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Relationships" do
4
- before :each do
5
- @manager = Phenomenal::Manager.instance
6
- @feature = Phenomenal::Feature.new(:feature)
7
- @context_names = [:a,:b,:c,:d,:e,:f,:g]
8
- @context_names.each do |name|
9
- @feature.context(name)
10
- end
11
-
12
- end
13
-
14
- after :each do
15
- force_forget_context(@feature)
16
- @context_names.each do |name|
17
- force_forget_context(name)
18
- end
19
- @manager.default_context.deactivate
20
- @manager.default_context.forget
21
- end
22
-
23
- describe Phenomenal::Feature do
24
- it "should be able to add requirements for contexts" do
25
- @feature.should respond_to :requirements_for
26
- @feature.method(:requirements_for).arity.should be(2),
27
- "Bad arity, should be 2"
28
- end
29
- it "should be able to add implications for contexts" do
30
- @feature.should respond_to :implications_for
31
- @feature.method(:implications_for).arity.should be(2),
32
- "Bad arity, should be 2"
33
- end
34
- it "should be able to add suggestions for contexts" do
35
- @feature.should respond_to :suggestions_for
36
- @feature.method(:suggestions_for).arity.should be(2),
37
- "Bad arity, should be 2"
38
- end
39
-
40
- describe "Requirements" do
41
- it "should store requirements" do
42
- @feature.requirements_for :a, :on=>[:b,:c,:d]
43
- @feature.requirements_for :a, :on=>:e
44
- @feature.relationships.should have(4).items
45
- end
46
-
47
- it "should avoid activation with missing requirements" do
48
- @feature.requirements_for :a, :on=>[:b,:c]
49
- phen_activate_context(:feature)
50
- expect {phen_activate_context(:a)}.to raise_error Phenomenal::Error
51
- phen_context_active?(:a).should be_false
52
- end
53
-
54
- it "should allow activation with all requirements" do
55
- phen_activate_context(:feature)
56
- phen_activate_context(:b)
57
- phen_activate_context(:c)
58
- expect {phen_activate_context(:a)}.to_not raise_error
59
- phen_context_active?(:a).should be_true
60
- end
61
-
62
- it "should deactivate source when target requirement is deactivated" do
63
- @feature.requirements_for :a, :on=>[:b,:c]
64
- phen_activate_context(:feature)
65
- phen_activate_context(:b)
66
- phen_activate_context(:c)
67
- phen_activate_context(:a)
68
- expect {phen_deactivate_context(:b)}.to_not raise_error
69
- phen_context_active?(:a).should be_false
70
- end
71
-
72
- it "should avoid feature activation when adding a not satisfied requirement" do
73
- @feature.requirements_for :a, :on=>[:b,:c]
74
- phen_activate_context(:a)
75
- expect{phen_activate_context(:feature)}.to_not raise_error
76
- phen_context_active?(:feature).should be_false
77
- end
78
-
79
- after do
80
- @manager.default_context.deactivate
81
- @manager.default_context.forget
82
- end
83
- it "should be possible to add requirements to the default context" do
84
- requirements_for :a, :on=>[:b,:c,:d]
85
- requirements_for :a, :on=>:e
86
- @manager.default_context.relationships.should have(4).items
87
- end
88
-
89
- it "should be possible to put requirements in the nested contexts" do
90
- feature :feature do
91
- context :a do
92
- requires :b
93
- end
94
- end
95
- @feature.relationships.should have(1).items
96
- end
97
-
98
- it "should be possible to put requirements in combined nested contexts" do
99
- feature :feature do
100
- context :a,:b do
101
- requires :c,:d,:e
102
- end
103
- end
104
- @feature.relationships.should have(3).items
105
- end
106
- end
107
- describe "Implications" do
108
- it "should store implications" do
109
- @feature.implications_for :a, :on=>[:b,:c,:d]
110
- @feature.implications_for :a, :on=>:e
111
- @feature.relationships.should have(4).items
112
- end
113
-
114
- it "should activate target when source is activated" do
115
- @feature.implications_for :a, :on=>:b
116
- @feature.activate
117
- expect {phen_activate_context(:a)}.to_not raise_error
118
- phen_context_active?(:a).should be_true
119
- phen_context_active?(:b).should be_true
120
- end
121
-
122
- it "should deactivate target when source is deactivated" do
123
- @feature.implications_for :a, :on=>:b
124
- @feature.activate
125
- phen_activate_context(:a)
126
- phen_deactivate_context(:a)
127
- phen_context_active?(:b).should be_false
128
- end
129
-
130
- it "should deactivate source when target is deactivated" do
131
- @feature.implications_for :a, :on=>:b
132
- @feature.activate
133
- phen_activate_context(:a)
134
- phen_deactivate_context(:b)
135
- phen_context_active?(:a).should be_false
136
- end
137
-
138
- it "should be possible to put implications in the nested contexts" do
139
- feature :feature do
140
- context :a do
141
- implies :b
142
- end
143
- end
144
- @feature.relationships.should have(1).items
145
- end
146
-
147
- it "should be possible to put implications in combined nested contexts" do
148
- feature :feature do
149
- context :a,:b do
150
- implies :c,:d,:e
151
- end
152
- end
153
- @feature.relationships.should have(3).items
154
- end
155
- end
156
-
157
- describe "Suggestions" do
158
- it "should be working on the default feature" do
159
- suggestions_for :a,:on=>:b
160
- @manager.default_context.relationships.should have(1).items
161
- context(:a).active?.should be_false
162
- context(:b).active?.should be_false
163
- expect {activate_context :a}.to_not raise_error
164
- context(:a).active?.should be_true
165
- context(:b).active?.should be_true
166
- expect {deactivate_context :a}.to_not raise_error
167
- context(:a).active?.should be_false
168
- context(:b).active?.should be_false
169
- #TODO forget default
170
- end
171
-
172
- it "should be possible to add relationships on active features" do
173
- context(:a).active?.should be_false
174
- context(:b).active?.should be_false
175
- expect {activate_context :a}.to_not raise_error
176
- suggestions_for :a,:on=>:b
177
- @manager.default_context.relationships.should have(1).items
178
- context(:a).active?.should be_true
179
- context(:b).active?.should be_true
180
- expect {deactivate_context :a}.to_not raise_error
181
- context(:a).active?.should be_false
182
- context(:b).active?.should be_false
183
- end
184
-
185
- it "should apply the relationship on the activation of the feature that contain it" do
186
- context(:a).active?.should be_false
187
- context(:b).active?.should be_false
188
- expect {activate_context :a}.to_not raise_error
189
- @feature.suggestions_for :a,:on=>:b
190
- context(:a).active?.should be_true
191
- context(:b).active?.should be_false
192
- expect {activate_context @feature}.to_not raise_error
193
- context(:a).active?.should be_true
194
- context(:b).active?.should be_true
195
- expect {deactivate_context @feature}.to_not raise_error
196
- context(:a).active?.should be_true
197
- context(:b).active?.should be_false
198
- end
199
-
200
- it "should store suggestions" do
201
- @feature.suggestions_for :a, :on=>[:b,:c,:d]
202
- @feature.suggestions_for :a, :on=>:e
203
- @feature.relationships.should have(4).items
204
- end
205
-
206
- it "should activate target when source is activated" do
207
- @feature.suggestions_for :a, :on=>:b
208
- @feature.activate
209
- expect {phen_activate_context(:a)}.to_not raise_error
210
- phen_context_active?(:a).should be_true
211
- phen_context_active?(:b).should be_true
212
- end
213
-
214
- it "should deactivate target when source is deactivated" do
215
- @feature.suggestions_for :a, :on=>:b
216
- @feature.activate
217
- phen_activate_context(:a)
218
- phen_deactivate_context(:a)
219
- phen_context_active?(:b).should be_false
220
- end
221
-
222
- it "should not deactivate source when target is deactivated" do
223
- @feature.suggestions_for :a, :on=>:b
224
- @feature.activate
225
- phen_activate_context(:a)
226
- phen_deactivate_context(:b)
227
- phen_context_active?(:a).should be_true
228
- end
229
-
230
- it "should be possible to put suggestions in the nested contexts" do
231
- feature :feature do
232
- context :a do
233
- suggests :b
234
- end
235
- end
236
- @feature.relationships.should have(1).items
237
- end
238
-
239
- it "should be possible to put suggestions in combined nested contexts" do
240
- feature :feature do
241
- context :a,:b do
242
- suggests :c,:d,:e
243
- end
244
- end
245
- @feature.relationships.should have(3).items
246
- end
247
- end
248
- end
249
- end
@@ -1,268 +0,0 @@
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
-