phenomenal 0.11.11.24.4 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README +3 -4
- data/Rakefile +3 -0
- data/lib/phenomenal.rb +15 -2
- data/lib/phenomenal/adaptation.rb +22 -12
- data/lib/phenomenal/context.rb +127 -134
- data/lib/phenomenal/dsl.rb +41 -14
- data/lib/phenomenal/feature.rb +8 -0
- data/lib/phenomenal/logger.rb +0 -1
- data/lib/phenomenal/manager.rb +117 -35
- 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/{test → spec}/test_classes.rb +3 -0
- metadata +69 -24
- data/demo.rb +0 -24
- data/demo_age.rb +0 -89
- data/demo_dsl.rb +0 -28
- data/phenomenal-0.11.11.24.3.gem +0 -0
- data/phenomenal.gemspec +0 -15
- data/test/test_cop_adaptation.rb +0 -168
- data/test/test_cop_composition.rb +0 -84
- data/test/test_cop_conflictpolicy.rb +0 -177
- data/test/test_cop_infrastructure.rb +0 -129
- data/test_declaration.rb +0 -18
@@ -1,129 +0,0 @@
|
|
1
|
-
require_relative "../lib/phenomenal.rb"
|
2
|
-
require "test/unit"
|
3
|
-
|
4
|
-
class TestCopInfrastructure < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@cm = Phenomenal::Manager.instance
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_protocol
|
10
|
-
context = Phenomenal::Context.new(:test)
|
11
|
-
assert(Phenomenal::Context, "The class Phenomenal::Context doesn't exist")
|
12
|
-
assert(@cm, "The class @cm exist")
|
13
|
-
assert_respond_to(context, :activate, "The activate method doesn't exist")
|
14
|
-
assert_respond_to(context, :deactivate,
|
15
|
-
"The deactivate method doesn't exist")
|
16
|
-
assert_respond_to(context, :active?, "The is_active method doesn't exist")
|
17
|
-
@cm.unregister_context(context)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_creation
|
21
|
-
context = Phenomenal::Context.new(:test)
|
22
|
-
assert_kind_of(Phenomenal::Context, context,
|
23
|
-
"A fresh instance should be contexts indeed")
|
24
|
-
assert(
|
25
|
-
(context.active?.is_a?(TrueClass) || context.active?.is_a?(FalseClass)),
|
26
|
-
"The context should be either active (true) or inactive (false).")
|
27
|
-
assert(!context.active?, "A fresh context should not be initially active.")
|
28
|
-
@cm.unregister_context(context)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_activation
|
32
|
-
context_name=:test
|
33
|
-
context = Phenomenal::Context.new(context_name)
|
34
|
-
assert(!context.active?, "A fresh context should not be initially active.")
|
35
|
-
assert_equal(context,context.activate,
|
36
|
-
"Phenomenal::Context activation should return the context")
|
37
|
-
assert(context.active?,
|
38
|
-
"Activation should leave the context in an active state")
|
39
|
-
assert_equal(context,context.deactivate,
|
40
|
-
"Phenomenal::Context deactivation should return the context")
|
41
|
-
assert(!context.active?,
|
42
|
-
"Deactivation should leave the context in an inactive state")
|
43
|
-
@cm.unregister_context(context)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_redundant_activation
|
47
|
-
context = Phenomenal::Context.new(:test)
|
48
|
-
assert(!context.active?, "A fresh context should not be initially active.")
|
49
|
-
10.times { context.activate }
|
50
|
-
assert(context.active?,
|
51
|
-
"Activation should leave the context in an active state")
|
52
|
-
9.times { context.deactivate }
|
53
|
-
assert(context.active?,
|
54
|
-
"Should stay active for fewer deactivations than activations")
|
55
|
-
context.deactivate
|
56
|
-
assert(!context.active?,
|
57
|
-
"Should become inactive after matching number of deactivations")
|
58
|
-
@cm.unregister_context(context)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_redundant_deactivation
|
62
|
-
context = Phenomenal::Context.new(:test)
|
63
|
-
assert(!context.active?, "A fresh context should not be initially active.")
|
64
|
-
3.times { context.activate }
|
65
|
-
assert(context.active?,
|
66
|
-
"Activation should leave the context in an active state")
|
67
|
-
9.times { context.deactivate }
|
68
|
-
assert(!context.active?,
|
69
|
-
"More deactivation than activation leave the context inactive")
|
70
|
-
context.activate
|
71
|
-
assert(context.active?,
|
72
|
-
"Deactivation does not accumulate once the context is already inactive")
|
73
|
-
context.deactivate
|
74
|
-
assert(!context.active?,
|
75
|
-
"Deactivation does not accumulate once the context is already inactive")
|
76
|
-
@cm.unregister_context(context)
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_context_name
|
80
|
-
context_name = :test
|
81
|
-
context = Phenomenal::Context.new(context_name)
|
82
|
-
assert_respond_to(context, :name, "Contexts should have a name")
|
83
|
-
assert_equal(context_name,context.name,
|
84
|
-
"A fresh context should be the definition name")
|
85
|
-
@cm.unregister_context(context)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_default
|
89
|
-
assert_nothing_raised(Phenomenal::Error,"Default context should exist"){
|
90
|
-
@cm.default_context.informations[:name]}
|
91
|
-
|
92
|
-
assert(@cm.default_context.active?,
|
93
|
-
"The default context should normally be active")
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_default_forget
|
97
|
-
old_informations = @cm.default_context.informations
|
98
|
-
assert_respond_to(@cm, :unregister_context,
|
99
|
-
"Method to drop unneeded contexts should exist")
|
100
|
-
assert(@cm.default_context.active?,
|
101
|
-
"The default context should be initialy active")
|
102
|
-
assert_raise(Phenomenal::Error,
|
103
|
-
"An active context cannot be thrown away"){
|
104
|
-
@cm.default_context.forget }
|
105
|
-
@cm.default_context.deactivate
|
106
|
-
assert(!@cm.default_context.active?, "Default should be inactive")
|
107
|
-
assert_nothing_raised(Phenomenal::Error,
|
108
|
-
"It should be possible to forget an inactive context"){
|
109
|
-
@cm.default_context.forget }
|
110
|
-
assert_nothing_raised(Phenomenal::Error,
|
111
|
-
%(Default context assumptions should hold for freshly
|
112
|
-
created default context)){
|
113
|
-
@cm.default_context.activate }
|
114
|
-
#TODO
|
115
|
-
#assert(old_informations[:creation_time]!=
|
116
|
-
#@cm.context_informations(:default)[:creation_time],
|
117
|
-
#"Fresh default context should not be the default context just forgotten")
|
118
|
-
assert(@cm.default_context.activate, "Default should be active")
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_adaptation_api
|
122
|
-
assert_respond_to(@cm, :register_adaptation,
|
123
|
-
"Phenomenal::Context manager should allow to adapt methods")
|
124
|
-
|
125
|
-
assert_respond_to(@cm, :unregister_adaptation,
|
126
|
-
"Phenomenal::Context manager should allow to deadapt methods")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
data/test_declaration.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative 'lib/phenomenal.rb'
|
2
|
-
class TestClass
|
3
|
-
def print(p)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class Phenomenal::TestDeclaration
|
8
|
-
act_as_context :persistent
|
9
|
-
|
10
|
-
adaptations_for TestClass
|
11
|
-
adapt :print do |p|
|
12
|
-
puts p
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Phenomenal::Manager.instance.find_context("Phenomenal::TestDeclaration").activate
|
17
|
-
puts Phenomenal::Manager.instance.find_context("Phenomenal::TestDeclaration").persistent
|
18
|
-
TestClass.new.print("plop")
|