phenomenal 0.99.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Rakefile +1 -7
  2. data/lib/phenomenal.rb +10 -1
  3. data/lib/phenomenal/adaptation.rb +6 -8
  4. data/lib/phenomenal/conflict_policies.rb +2 -1
  5. data/lib/phenomenal/context.rb +36 -31
  6. data/lib/phenomenal/dsl.rb +14 -9
  7. data/lib/phenomenal/feature.rb +1 -0
  8. data/lib/phenomenal/manager.rb +10 -12
  9. data/lib/phenomenal/proc.rb +2 -2
  10. data/lib/phenomenal/relationships/context_relationships.rb +2 -0
  11. data/lib/phenomenal/relationships/dsl.rb +1 -0
  12. data/lib/phenomenal/relationships/feature_relationships.rb +2 -2
  13. data/lib/phenomenal/relationships/implication.rb +10 -4
  14. data/lib/phenomenal/relationships/relationship.rb +13 -0
  15. data/lib/phenomenal/relationships/relationships_manager.rb +1 -1
  16. data/lib/phenomenal/relationships/relationships_store.rb +13 -7
  17. data/lib/phenomenal/relationships/requirement.rb +5 -0
  18. data/lib/phenomenal/relationships/suggestion.rb +14 -6
  19. data/lib/phenomenal/version.rb +1 -1
  20. data/lib/phenomenal/viewer/dsl.rb +15 -0
  21. data/lib/phenomenal/viewer/graphical.rb +136 -0
  22. data/lib/phenomenal/viewer/textual.rb +36 -0
  23. data/spec/context_spec.rb +93 -27
  24. data/spec/dsl_spec.rb +0 -39
  25. data/spec/integration/adaptation_spec.rb +127 -0
  26. data/spec/integration/combined_contexts_spec.rb +48 -0
  27. data/spec/integration/composition_spec.rb +62 -0
  28. data/spec/integration/conflict_policy_spec.rb +143 -0
  29. data/spec/integration/open_context.rb +48 -0
  30. data/spec/{behavior → integration}/relationships_spec.rb +0 -6
  31. data/spec/manager_spec.rb +30 -19
  32. data/spec/relationships/context_relationships_spec.rb +23 -3
  33. data/spec/relationships/dsl_spec.rb +9 -3
  34. data/spec/relationships/feature_relationships_spec.rb +22 -3
  35. data/spec/relationships/relationship_spec.rb +13 -1
  36. data/spec/relationships/relationships_manager_spec.rb +0 -11
  37. data/spec/relationships/relationships_store_spec.rb +31 -7
  38. data/spec/spec_helper.rb +1 -0
  39. data/spec/test_classes.rb +3 -0
  40. metadata +16 -13
  41. data/spec/behavior/adaptation_spec.rb +0 -5
  42. data/spec/behavior/combined_contexts_spec.rb +0 -5
  43. data/spec/behavior/composition_spec.rb +0 -5
  44. data/spec/behavior/conflict_policy_spec.rb +0 -5
  45. data/spec/behavior/open_context.rb +0 -5
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe "Open context facilities" do
4
+ before :each do
5
+ context(:quiet) do
6
+ adaptations_for Phone
7
+ adapt :advertise do |a_call|
8
+ "vibrator"
9
+ end
10
+ end
11
+
12
+ context(:offHook) do
13
+ adaptations_for Phone
14
+ adapt :advertise do |a_call|
15
+ "call waiting signal"
16
+ end
17
+ end
18
+ end
19
+
20
+ after :each do
21
+ force_forget_context(:screening)
22
+ force_forget_context(:test)
23
+ end
24
+
25
+ it "should be possible to open an existent context and add adaptations in it" do
26
+ phone = Phone.new
27
+ call = Call.new("Bob")
28
+ phone.receive(call)
29
+
30
+ activate_context(:quiet)
31
+ phen_context_active?(:quiet).should be_true
32
+ context :quiet do
33
+ remove_adaptation(Phone,:advertise,true)
34
+ end
35
+
36
+ phone.advertise(call).should=="ringtone"
37
+
38
+ context :quiet do
39
+ adaptations_for Phone
40
+ adapt :advertise {|a_call| "vibrator" }
41
+ end
42
+
43
+ phone.advertise(call).should=="vibrator"
44
+ deactivate_context(:quiet)
45
+
46
+ phone.advertise(call).should=="ringtone"
47
+ end
48
+ end
@@ -8,7 +8,6 @@ describe "Relationships" do
8
8
  @context_names.each do |name|
9
9
  @feature.context(name)
10
10
  end
11
-
12
11
  end
13
12
 
14
13
  after :each do
@@ -76,10 +75,6 @@ describe "Relationships" do
76
75
  phen_context_active?(:feature).should be_false
77
76
  end
78
77
 
79
- after do
80
- @manager.default_context.deactivate
81
- @manager.default_context.forget
82
- end
83
78
  it "should be possible to add requirements to the default context" do
84
79
  requirements_for :a, :on=>[:b,:c,:d]
85
80
  requirements_for :a, :on=>:e
@@ -166,7 +161,6 @@ describe "Relationships" do
166
161
  expect {deactivate_context :a}.to_not raise_error
167
162
  context(:a).active?.should be_false
168
163
  context(:b).active?.should be_false
169
- #TODO forget default
170
164
  end
171
165
 
172
166
  it "should be possible to add relationships on active features" do
data/spec/manager_spec.rb CHANGED
@@ -14,31 +14,42 @@ describe Phenomenal::Manager do
14
14
  end
15
15
 
16
16
  describe "#register_context" do
17
- pending "TODO"
17
+ it "should save the context when they are defined" do
18
+ @manager.contexts[@context].should==@context
19
+ end
20
+
21
+ it "should raise an error if we declare a context with a name already used" do
22
+ #expect{Phenomenal::Context.new(:test)}.to raise_error Phenomenal::Error
23
+ end
24
+
25
+ it "should raise an error if we try to register a context twice" do
26
+ expect{@manager.register_context(@context)}.to raise_error Phenomenal::Error
27
+ end
18
28
  end
19
29
 
20
30
  describe "#unregister_context" do
21
- pending "TODO"
22
- end
23
-
24
- describe "#register_adaptation" do
25
- pending "unregister_adaptation"
26
- end
27
-
28
- describe "#activate_context" do
29
- pending "TODO"
30
- end
31
-
32
- describe "#deactivate_context" do
33
- pending "TODO"
34
- end
35
-
36
- describe "#proceed" do
37
- pending "TODO"
31
+ it "should remove contexts from the manager" do
32
+ context = Phenomenal::Context.new(:context)
33
+ expect{@manager.unregister_context(context)}.to_not raise_error
34
+ @manager.contexts[context].should be_nil
35
+ end
36
+
37
+ it "should allow to forget default context only when it is the only defined context" do
38
+ @manager.contexts.size.should==4
39
+ expect{@manager.unregister_context(@manager.default_context)}.to raise_error Phenomenal::Error
40
+ force_forget_context(@context)
41
+ force_forget_context(@context2)
42
+ @manager.contexts.size.should==1
43
+ expect{@manager.unregister_context(@manager.default_context)}.to_not raise_error
44
+ @context = Phenomenal::Context.new(:test)
45
+ @context2 = Phenomenal::Context.new(:test2)
46
+ end
38
47
  end
39
48
 
40
49
  describe "#change_conflict_policy" do
41
- pending "TODO"
50
+ it "should be possible to change the conflict policy" do
51
+ @manager.should respond_to :change_conflict_policy
52
+ end
42
53
  end
43
54
 
44
55
  describe "#find_context" do
@@ -1,13 +1,33 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Phenomenal::ContextRelationships do
4
+ before :each do
5
+ @feature = Phenomenal::Feature.new :feature
6
+ @context = @feature.context(:context)
7
+ end
8
+ after :each do
9
+ force_forget_context(@feature)
10
+ force_forget_context(context(:context))
11
+ end
4
12
  describe "#requires" do
5
- pending "TODO"
13
+ it "should store the requirements in the parent feature" do
14
+ @context.requires :b
15
+ @feature.relationships.should have(1).item
16
+ @feature.relationships.first.is_a?(Phenomenal::Requirement).should be_true
17
+ end
6
18
  end
7
19
  describe "#implies" do
8
- pending "TODO"
20
+ it "should store the implications in the parent feature" do
21
+ @context.implies :b
22
+ @feature.relationships.should have(1).item
23
+ @feature.relationships.first.is_a?(Phenomenal::Implication).should be_true
24
+ end
9
25
  end
10
26
  describe "#suggests" do
11
- pending "TODO"
27
+ it "should store the suggestions in the parent feature" do
28
+ @context.suggests :b
29
+ @feature.relationships.should have(1).item
30
+ @feature.relationships.first.is_a?(Phenomenal::Suggestion).should be_true
31
+ end
12
32
  end
13
33
  end
@@ -2,12 +2,18 @@ require "spec_helper"
2
2
 
3
3
  describe Phenomenal::DSL do
4
4
  describe "#requirements_for" do
5
- pending "TODO"
5
+ it "should exist in Kernel" do
6
+ Kernel.should respond_to :requirements_for
7
+ end
6
8
  end
7
9
  describe "#implications_for" do
8
- pending "TODO"
10
+ it "should exist in Kernel" do
11
+ Kernel.should respond_to :implications_for
12
+ end
9
13
  end
10
14
  describe "#suggestions_for" do
11
- pending "TODO"
15
+ it "should exist in Kernel" do
16
+ Kernel.should respond_to :suggestions_for
17
+ end
12
18
  end
13
19
  end
@@ -1,13 +1,32 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Phenomenal::FeatureRelationships do
4
+ before :each do
5
+ @feature = Phenomenal::Feature.new :feature
6
+ end
7
+ after :each do
8
+ force_forget_context(@feature)
9
+ end
10
+
4
11
  describe "#requirements_for" do
5
- pending "TODO"
12
+ it "should store the requirements" do
13
+ @feature.requirements_for :a,:on=>:b
14
+ @feature.relationships.should have(1).item
15
+ @feature.relationships.first.is_a?(Phenomenal::Requirement).should be_true
16
+ end
6
17
  end
7
18
  describe "#implications_for" do
8
- pending "TODO"
19
+ it "should store the implications" do
20
+ @feature.implications_for :a,:on=>:b
21
+ @feature.relationships.should have(1).item
22
+ @feature.relationships.first.is_a?(Phenomenal::Implication).should be_true
23
+ end
9
24
  end
10
25
  describe "#suggestions_for" do
11
- pending "TODO"
26
+ it "should store the suggestions" do
27
+ @feature.suggestions_for :a,:on=>:b
28
+ @feature.relationships.should have(1).item
29
+ @feature.relationships.first.is_a?(Phenomenal::Suggestion).should be_true
30
+ end
12
31
  end
13
32
  end
@@ -16,6 +16,8 @@ describe Phenomenal::Relationship do
16
16
  a.should_not == d
17
17
  e = Phenomenal::Relationship.new(:other_source,:target,nil)
18
18
  a.should_not == e
19
+ e = Phenomenal::Relationship.new(:other_source,:target,:test)
20
+ a.should_not == e
19
21
  end
20
22
 
21
23
  it "should be false for relationships of different types" do
@@ -26,6 +28,16 @@ describe Phenomenal::Relationship do
26
28
  end
27
29
 
28
30
  describe "#refresh" do
29
- pending "TODO"
31
+ it "should update the references of the source and the target contexts" do
32
+ a = Phenomenal::Implication.new(:source,:target,nil)
33
+ expect{a.refresh}.to_not raise_error
34
+ context :source
35
+ context :target
36
+ a.refresh
37
+ a.source.should==context(:source)
38
+ a.target.should==context(:target)
39
+ force_forget_context(:source)
40
+ force_forget_context(:target)
41
+ end
30
42
  end
31
43
  end
@@ -1,15 +1,4 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Phenomenal::RelationshipsManager do
4
- describe "#activate_relationships" do
5
- pending "TODO"
6
- end
7
-
8
- describe "#deactivate_relationships" do
9
- pending "TODO"
10
- end
11
-
12
- describe "#update_relationships_references" do
13
- pending "TODO"
14
- end
15
4
  end
@@ -1,19 +1,43 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Phenomenal::RelationshipsStore do
4
- describe "#add" do
5
- pending "TODO"
4
+ before :each do
5
+ @source = context :source
6
+ @target = context :target
7
+ @relationship = Phenomenal::Relationship.new(:source,:target,phen_default_context)
8
+ @relationship2 = Phenomenal::Relationship.new(:source2,:target2,phen_default_context)
9
+ @relationship12 = Phenomenal::Relationship.new(:source,:target2,phen_default_context)
10
+ @store = Phenomenal::RelationshipsStore.new
6
11
  end
7
12
 
8
- describe "#remove" do
9
- pending "TODO"
13
+ after :each do
14
+ force_forget_context(@source)
15
+ force_forget_context(@target)
16
+ end
17
+
18
+ describe "#add" do
19
+ it "should add the relationship to the store" do
20
+ @store.add(@relationship)
21
+ @store.include?(@relationship).should be_true
22
+ end
10
23
  end
11
24
 
12
- describe "#update_references" do
13
- pending "TODO"
25
+ describe "#remove" do
26
+ it "should remove the relationship from the store" do
27
+ @store.add(@relationship)
28
+ @store.remove(@relationship)
29
+ @store.include?(@relationship).should be_false
30
+ end
14
31
  end
15
32
 
16
33
  describe "#get_for" do
17
- pending "TODO"
34
+ it "should return the relationships that concern the target" do
35
+ @store.add(@relationship)
36
+ @store.add(@relationship2)
37
+ @store.add(@relationship12)
38
+ @store.get_for(@source).should include(@relationship)
39
+ @store.get_for(@source).should include(@relationship12)
40
+ @store.get_for(@source).should_not include(@relationship2)
41
+ end
18
42
  end
19
43
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rspec'
2
2
  require "phenomenal"
3
+ require "test_classes.rb"
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.color_enabled = true
data/spec/test_classes.rb CHANGED
@@ -2,6 +2,9 @@
2
2
  class TestString < String
3
3
  end
4
4
 
5
+ class TestString2 < String
6
+ end
7
+
5
8
  class TestClass < String
6
9
  @klass_inst_var = 2
7
10
  @@klass_var = 1
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: phenomenal
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.99.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Loic Vigneron - Thibault Poncelet
@@ -36,6 +36,9 @@ files:
36
36
  - lib/phenomenal/feature.rb
37
37
  - lib/phenomenal/proc.rb
38
38
  - lib/phenomenal/conflict_policies.rb
39
+ - lib/phenomenal/viewer/graphical.rb
40
+ - lib/phenomenal/viewer/textual.rb
41
+ - lib/phenomenal/viewer/dsl.rb
39
42
  - lib/phenomenal/dsl.rb
40
43
  - lib/phenomenal/version.rb
41
44
  - lib/phenomenal/relationships/implication.rb
@@ -57,12 +60,6 @@ files:
57
60
  - spec/spec_helper.rb
58
61
  - spec/feature_spec.rb
59
62
  - spec/context_spec.rb
60
- - spec/behavior/composition_spec.rb
61
- - spec/behavior/combined_contexts_spec.rb
62
- - spec/behavior/adaptation_spec.rb
63
- - spec/behavior/open_context.rb
64
- - spec/behavior/conflict_policy_spec.rb
65
- - spec/behavior/relationships_spec.rb
66
63
  - spec/test_classes.rb
67
64
  - spec/manager_spec.rb
68
65
  - spec/adaptation_spec.rb
@@ -74,6 +71,12 @@ files:
74
71
  - spec/relationships/relationships_manager_spec.rb
75
72
  - spec/dsl_spec.rb
76
73
  - spec/proc_spec.rb
74
+ - spec/integration/composition_spec.rb
75
+ - spec/integration/combined_contexts_spec.rb
76
+ - spec/integration/adaptation_spec.rb
77
+ - spec/integration/open_context.rb
78
+ - spec/integration/conflict_policy_spec.rb
79
+ - spec/integration/relationships_spec.rb
77
80
  homepage: http://www.phenomenal-gem.com
78
81
  licenses: []
79
82
 
@@ -105,12 +108,6 @@ test_files:
105
108
  - spec/spec_helper.rb
106
109
  - spec/feature_spec.rb
107
110
  - spec/context_spec.rb
108
- - spec/behavior/composition_spec.rb
109
- - spec/behavior/combined_contexts_spec.rb
110
- - spec/behavior/adaptation_spec.rb
111
- - spec/behavior/open_context.rb
112
- - spec/behavior/conflict_policy_spec.rb
113
- - spec/behavior/relationships_spec.rb
114
111
  - spec/test_classes.rb
115
112
  - spec/manager_spec.rb
116
113
  - spec/adaptation_spec.rb
@@ -122,3 +119,9 @@ test_files:
122
119
  - spec/relationships/relationships_manager_spec.rb
123
120
  - spec/dsl_spec.rb
124
121
  - spec/proc_spec.rb
122
+ - spec/integration/composition_spec.rb
123
+ - spec/integration/combined_contexts_spec.rb
124
+ - spec/integration/adaptation_spec.rb
125
+ - spec/integration/open_context.rb
126
+ - spec/integration/conflict_policy_spec.rb
127
+ - spec/integration/relationships_spec.rb
@@ -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