aquarium 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +53 -0
- data/README +20 -4
- data/Rakefile +19 -4
- data/UPGRADE +41 -1
- data/examples/aspect_design_example.rb +4 -1
- data/examples/aspect_design_example_spec.rb +41 -0
- data/examples/design_by_contract_example.rb +2 -3
- data/examples/design_by_contract_example_spec.rb +92 -0
- data/examples/method_missing_example.rb +1 -1
- data/examples/method_missing_example_spec.rb +59 -0
- data/examples/method_tracing_example.rb +4 -2
- data/examples/method_tracing_example_spec.rb +141 -0
- data/lib/aquarium/aspects/advice.rb +2 -2
- data/lib/aquarium/aspects/aspect.rb +20 -35
- data/lib/aquarium/aspects/dsl.rb +2 -1
- data/lib/aquarium/aspects/dsl/aspect_dsl.rb +12 -8
- data/lib/aquarium/aspects/dsl/object_dsl.rb +8 -0
- data/lib/aquarium/aspects/join_point.rb +16 -10
- data/lib/aquarium/aspects/pointcut.rb +3 -3
- data/lib/aquarium/extras/design_by_contract.rb +20 -11
- data/lib/aquarium/utils.rb +1 -0
- data/lib/aquarium/utils/method_utils.rb +41 -0
- data/lib/aquarium/utils/name_utils.rb +35 -0
- data/lib/aquarium/utils/type_utils.rb +9 -0
- data/lib/aquarium/version.rb +3 -5
- data/rake_tasks/examples.rake +1 -1
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +30 -28
- data/spec/aquarium/aspects/aspect_spec.rb +90 -0
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +5 -3
- data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +3 -1
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +174 -110
- data/spec/aquarium/aspects/join_point_spec.rb +120 -19
- data/spec/aquarium/aspects/pointcut_spec.rb +24 -14
- data/spec/aquarium/extras/design_by_contract_spec.rb +3 -0
- data/spec/aquarium/finders/finder_result_spec.rb +1 -1
- data/spec/aquarium/finders/method_finder_spec.rb +3 -4
- data/spec/aquarium/spec_example_classes.rb +4 -0
- data/spec/aquarium/utils/method_utils_spec.rb +124 -1
- data/spec/aquarium/utils/name_utils_spec.rb +56 -0
- data/spec/aquarium/utils/type_utils_spec.rb +17 -0
- metadata +12 -4
- data/spec/aquarium/finders/method_sorting_spec.rb +0 -16
@@ -25,37 +25,138 @@ describe Aquarium::Aspects::JoinPoint, "#initialize with invalid parameters" do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe Aquarium::Aspects::JoinPoint, "#initialize with
|
28
|
+
describe Aquarium::Aspects::JoinPoint, "#initialize with parameters that specify class vs. instance methods" do
|
29
29
|
it "should assume the :method_name refers to an instance method, by default." do
|
30
30
|
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split
|
31
|
-
jp.
|
31
|
+
jp.instance_method?.should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should treat the :method_name as refering to an instance method if :instance_method is specified as true." do
|
35
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :instance_method => true
|
36
|
+
jp.instance_method?.should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should treat the :method_name as refering to a class method if :instance_method is specified as false." do
|
40
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :instance_method => false
|
41
|
+
jp.instance_method?.should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should treat the :method_name as refering to an instance method if :class_method is specified as false." do
|
45
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :class_method => false
|
46
|
+
jp.instance_method?.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should treat the :method_name as refering to a class method if :class_method is specified as true." do
|
50
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :class_method => true
|
51
|
+
jp.instance_method?.should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should treat give precedence to :instance_method if appears with :class_method." do
|
55
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :instance_method => false, :class_method => true
|
56
|
+
jp.instance_method?.should be_false
|
57
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => String, :method => :split, :instance_method => true, :class_method => false
|
58
|
+
jp.instance_method?.should be_true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Aquarium::Aspects::JoinPoint, "#visibility" do
|
63
|
+
class ProtectionExample
|
64
|
+
def public_instance_m; end
|
65
|
+
protected
|
66
|
+
def protected_instance_m; end
|
67
|
+
private
|
68
|
+
def private_instance_m; end
|
69
|
+
def self.public_class_m; end
|
70
|
+
def self.private_class_m; end
|
71
|
+
private_class_method :private_class_m
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return :public for public instance methods." do
|
75
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :public_instance_m
|
76
|
+
jp.visibility.should == :public
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return :public for public instance methods, when only instance methods are specified." do
|
80
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :public_instance_m, :instance_method => true
|
81
|
+
jp.visibility.should == :public
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return :public for public class methods, when only class methods are specified using :instance_method => false." do
|
85
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :public_class_m, :instance_method => false
|
86
|
+
jp.visibility.should == :public
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return :public for public instance methods, when only instance methods are specified using :class_method => false." do
|
90
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :public_instance_m, :class_method => false
|
91
|
+
jp.visibility.should == :public
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return :public for public class methods, when only class methods are specified." do
|
95
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :public_class_m, :class_method => true
|
96
|
+
jp.visibility.should == :public
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return :protected for protected instance methods." do
|
100
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :protected_instance_m
|
101
|
+
jp.visibility.should == :protected
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return :protected for protected instance methods, when only instance methods are specified." do
|
105
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :protected_instance_m, :instance_method => true
|
106
|
+
jp.visibility.should == :protected
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return nil for protected class methods, when only class methods are specified using :instance_method => false." do
|
110
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :protected_class_method, :instance_method => false
|
111
|
+
jp.visibility.should == nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return :protected for protected instance methods, when only instance methods are specified using :class_method => false." do
|
115
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :protected_instance_m, :class_method => false
|
116
|
+
jp.visibility.should == :protected
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return nil for protected class methods, when only class methods are specified." do
|
120
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :protected_class_method, :class_method => true
|
121
|
+
jp.visibility.should == nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return :private for private instance methods." do
|
125
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :private_instance_m
|
126
|
+
jp.visibility.should == :private
|
32
127
|
end
|
33
128
|
|
34
|
-
it "should
|
35
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
36
|
-
jp.
|
129
|
+
it "should return :private for private instance methods, when only instance methods are specified." do
|
130
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :private_instance_m, :instance_method => true
|
131
|
+
jp.visibility.should == :private
|
37
132
|
end
|
38
133
|
|
39
|
-
it "should
|
40
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
41
|
-
jp.
|
134
|
+
it "should return :private for private class methods, when only class methods are specified using :instance_method => false." do
|
135
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :private_class_m, :instance_method => false
|
136
|
+
jp.visibility.should == :private
|
42
137
|
end
|
43
138
|
|
44
|
-
it "should
|
45
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
46
|
-
jp.
|
139
|
+
it "should return :private for private instance methods, when only instance methods are specified using :class_method => false." do
|
140
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :private_instance_m, :class_method => false
|
141
|
+
jp.visibility.should == :private
|
47
142
|
end
|
48
143
|
|
49
|
-
it "should
|
50
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
51
|
-
jp.
|
144
|
+
it "should return :private for private class methods, when only class methods are specified." do
|
145
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :private_class_m, :class_method => true
|
146
|
+
jp.visibility.should == :private
|
52
147
|
end
|
53
148
|
|
54
|
-
it "should
|
55
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
56
|
-
jp.
|
57
|
-
jp = Aquarium::Aspects::JoinPoint.new :type =>
|
58
|
-
jp.
|
149
|
+
it "should return nil for non-existent methods." do
|
150
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :foo
|
151
|
+
jp.visibility.should == nil
|
152
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :foo, :instance_method => true
|
153
|
+
jp.visibility.should == nil
|
154
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :foo, :instance_method => false
|
155
|
+
jp.visibility.should == nil
|
156
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :foo, :class_method => true
|
157
|
+
jp.visibility.should == nil
|
158
|
+
jp = Aquarium::Aspects::JoinPoint.new :type => ProtectionExample, :method => :foo, :class_method => false
|
159
|
+
jp.visibility.should == nil
|
59
160
|
end
|
60
161
|
end
|
61
162
|
|
@@ -11,8 +11,8 @@ def common_setup
|
|
11
11
|
@pub_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPublicInstanceMethod, :method_name => :public_instance_test_method
|
12
12
|
@pro_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithProtectedInstanceMethod, :method_name => :protected_instance_test_method
|
13
13
|
@pri_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPrivateInstanceMethod, :method_name => :private_instance_test_method
|
14
|
-
@cpub_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPublicClassMethod, :method_name => :public_class_test_method, :
|
15
|
-
@cpri_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPrivateClassMethod, :method_name => :private_class_test_method, :
|
14
|
+
@cpub_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPublicClassMethod, :method_name => :public_class_test_method, :class_method => true
|
15
|
+
@cpri_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPrivateClassMethod, :method_name => :private_class_test_method, :class_method => true
|
16
16
|
@apro_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithProtectedInstanceMethod, :method_name => :all
|
17
17
|
@apri_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPrivateInstanceMethod, :method_name => :all
|
18
18
|
@acpub_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithPublicClassMethod, :method_name => :all
|
@@ -146,6 +146,16 @@ describe Aquarium::Aspects::Pointcut, " (objects specified)" do
|
|
146
146
|
Aquarium::Aspects::JoinPoint.new(:object => pro, :method_name => :protected_instance_test_method),
|
147
147
|
Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :public_instance_test_method)])
|
148
148
|
end
|
149
|
+
|
150
|
+
it "does confuse strings specified with :objects as type names." do
|
151
|
+
string = "mystring"
|
152
|
+
lambda { Aquarium::Aspects::Pointcut.new :object => string, :methods => :capitalize }.should raise_error(NameError)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "does confuse symbols specified with :objects as type names." do
|
156
|
+
symbol = :mystring
|
157
|
+
lambda { Aquarium::Aspects::Pointcut.new :object => symbol, :methods => :capitalize }.should raise_error(NameError)
|
158
|
+
end
|
149
159
|
end
|
150
160
|
|
151
161
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with public instance methods)" do
|
@@ -221,7 +231,7 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with public
|
|
221
231
|
pc = Aquarium::Aspects::Pointcut.new :objects => pub, :method_options => [:public, :class, :suppress_ancestor_methods]
|
222
232
|
pc.join_points_matched.size.should == 0
|
223
233
|
pc.join_points_not_matched.size.should == 1
|
224
|
-
pc.join_points_not_matched.should eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :all, :
|
234
|
+
pc.join_points_not_matched.should eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :all, :class_method => true)]))
|
225
235
|
end
|
226
236
|
end
|
227
237
|
|
@@ -239,7 +249,7 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with private
|
|
239
249
|
it "should support MethodFinder's :private and :class options for the specified objects, which will return no methods." do
|
240
250
|
pri = ClassWithPrivateInstanceMethod.new
|
241
251
|
pc = Aquarium::Aspects::Pointcut.new :objects => pri, :method_options => [:private, :class, :suppress_ancestor_methods]
|
242
|
-
pc.join_points_not_matched.should eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pri, :method_name => :all, :
|
252
|
+
pc.join_points_not_matched.should eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pri, :method_name => :all, :class_method => true)]))
|
243
253
|
pc.join_points_not_matched.size.should == 1
|
244
254
|
end
|
245
255
|
end
|
@@ -308,23 +318,23 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
308
318
|
end
|
309
319
|
|
310
320
|
it "should match attribute specifications for types that are prefixed with @." do
|
311
|
-
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^@attr/]
|
321
|
+
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^@attr.*ClassWithAttribs/]
|
312
322
|
pc.join_points_matched.should == @expected_for_types
|
313
323
|
end
|
314
324
|
|
315
325
|
it "should match attribute specifications for objects that are prefixed with @." do
|
316
|
-
pc = Aquarium::Aspects::Pointcut.new :object => @object_of_ClassWithAttribs, :attributes => [/^@attr/]
|
326
|
+
pc = Aquarium::Aspects::Pointcut.new :object => @object_of_ClassWithAttribs, :attributes => [/^@attr.*ClassWithAttribs/]
|
317
327
|
pc.join_points_matched.should == @expected_for_objects
|
318
328
|
end
|
319
329
|
|
320
330
|
it "should match attribute specifications that are regular expressions of symbols." do
|
321
|
-
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^:attr/]
|
331
|
+
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^:attr.*ClassWithAttribs/]
|
322
332
|
pc.join_points_matched.should == @expected_for_types
|
323
333
|
end
|
324
334
|
|
325
335
|
it "should match attribute specifications for objects that are regular expressions of symbols." do
|
326
336
|
object = ClassWithAttribs.new
|
327
|
-
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr/]
|
337
|
+
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr.*ClassWithAttribs/]
|
328
338
|
pc.join_points_matched.should == Set.new([
|
329
339
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs),
|
330
340
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs=),
|
@@ -333,13 +343,13 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
333
343
|
end
|
334
344
|
|
335
345
|
it "should match public attribute readers and writers for types when both the :readers and :writers options are specified." do
|
336
|
-
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/], :attribute_options => [:readers, :writers]
|
346
|
+
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr.*ClassWithAttribs/], :attribute_options => [:readers, :writers]
|
337
347
|
pc.join_points_matched.should == @expected_for_types
|
338
348
|
end
|
339
349
|
|
340
350
|
it "should match public attribute readers and writers for objects when both the :readers and :writers options are specified." do
|
341
351
|
object = ClassWithAttribs.new
|
342
|
-
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr/], :attribute_options => [:readers, :writers]
|
352
|
+
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr.*ClassWithAttribs/], :attribute_options => [:readers, :writers]
|
343
353
|
pc.join_points_matched.should == Set.new([
|
344
354
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs),
|
345
355
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs=),
|
@@ -348,7 +358,7 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
348
358
|
end
|
349
359
|
|
350
360
|
it "should match public attribute readers for types only when the :readers option is specified." do
|
351
|
-
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/], :attribute_options => [:readers]
|
361
|
+
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr.*ClassWithAttribs/], :attribute_options => [:readers]
|
352
362
|
pc.join_points_matched.should == Set.new([
|
353
363
|
Aquarium::Aspects::JoinPoint.new(:type => "ClassWithAttribs", :method_name => :attrRW_ClassWithAttribs),
|
354
364
|
Aquarium::Aspects::JoinPoint.new(:type => "ClassWithAttribs", :method_name => :attrR_ClassWithAttribs)])
|
@@ -356,14 +366,14 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
356
366
|
|
357
367
|
it "should match public attribute readers for objects only when the :readers option is specified." do
|
358
368
|
object = ClassWithAttribs.new
|
359
|
-
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr/], :attribute_options => [:readers]
|
369
|
+
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr.*ClassWithAttribs/], :attribute_options => [:readers]
|
360
370
|
pc.join_points_matched.should == Set.new([
|
361
371
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs),
|
362
372
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrR_ClassWithAttribs)])
|
363
373
|
end
|
364
374
|
|
365
375
|
it "should match public attribute writers for types only when the :writers option is specified." do
|
366
|
-
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/], :attribute_options => [:writers]
|
376
|
+
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr.*ClassWithAttribs/], :attribute_options => [:writers]
|
367
377
|
pc.join_points_matched.should == Set.new([
|
368
378
|
Aquarium::Aspects::JoinPoint.new(:type => "ClassWithAttribs", :method_name => :attrRW_ClassWithAttribs=),
|
369
379
|
Aquarium::Aspects::JoinPoint.new(:type => "ClassWithAttribs", :method_name => :attrW_ClassWithAttribs=)])
|
@@ -371,7 +381,7 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
371
381
|
|
372
382
|
it "should match public attribute writers for objects only when the :writers option is specified." do
|
373
383
|
object = ClassWithAttribs.new
|
374
|
-
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr/], :attribute_options => [:writers]
|
384
|
+
pc = Aquarium::Aspects::Pointcut.new :object => object, :attributes => [/^:attr.*ClassWithAttribs/], :attribute_options => [:writers]
|
375
385
|
pc.join_points_matched.should == Set.new([
|
376
386
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrRW_ClassWithAttribs=),
|
377
387
|
Aquarium::Aspects::JoinPoint.new(:object => object, :method_name => :attrW_ClassWithAttribs=)])
|
@@ -3,6 +3,7 @@ require 'aquarium/extras/design_by_contract'
|
|
3
3
|
|
4
4
|
describe Aquarium::Extras::DesignByContract, "precondition" do
|
5
5
|
class PreCond
|
6
|
+
include Aquarium::Extras::DesignByContract
|
6
7
|
def action *args
|
7
8
|
end
|
8
9
|
|
@@ -22,6 +23,7 @@ end
|
|
22
23
|
|
23
24
|
describe Aquarium::Extras::DesignByContract, "postcondition" do
|
24
25
|
class PostCond
|
26
|
+
include Aquarium::Extras::DesignByContract
|
25
27
|
def action *args
|
26
28
|
end
|
27
29
|
|
@@ -43,6 +45,7 @@ end
|
|
43
45
|
|
44
46
|
describe Aquarium::Extras::DesignByContract, "invariant" do
|
45
47
|
class InvarCond
|
48
|
+
include Aquarium::Extras::DesignByContract
|
46
49
|
def initialize
|
47
50
|
@invar = 0
|
48
51
|
end
|
@@ -119,7 +119,7 @@ describe Aquarium::Finders::FinderResult, "#<<" do
|
|
119
119
|
it "should return self." do
|
120
120
|
result1 = Aquarium::Finders::FinderResult.new
|
121
121
|
result = result1 << Aquarium::Finders::FinderResult.new
|
122
|
-
result.object_id.should
|
122
|
+
result.object_id.should == result1.object_id
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should merge the value of the other FinderResult#not_matched into self's not_matched value." do
|
@@ -237,14 +237,13 @@ describe Aquarium::Finders::MethodFinder, "#find (searching for class methods)"
|
|
237
237
|
|
238
238
|
it "should find all class methods matching a regular expression for types when :class is used." do
|
239
239
|
# Have to add some rspec methods to the expected lists!
|
240
|
-
rspec_expected = %w[received_message?]
|
241
240
|
expected = {}
|
242
|
-
expected[Kernel] =
|
241
|
+
expected[Kernel] = [:chomp!, :chop!, :respond_to?]
|
243
242
|
[Object, Module, Class].each do |clazz|
|
244
|
-
expected[clazz] =
|
243
|
+
expected[clazz] = [:respond_to?]
|
245
244
|
end
|
246
245
|
class_array = [Kernel, Module, Object, Class]
|
247
|
-
actual = Aquarium::Finders::MethodFinder.new.find :types => class_array, :methods => [/^
|
246
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => class_array, :methods => [/^resp.*\?$/, /^ch.*\!$/], :options => :class
|
248
247
|
class_array.each do |c|
|
249
248
|
actual.matched[c].should == Set.new(expected[c])
|
250
249
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
# :enddoc:
|
2
|
+
|
3
|
+
require 'aquarium/aspects/dsl/aspect_dsl'
|
4
|
+
|
2
5
|
# Declares classes, etc. that support several different module specs.
|
3
6
|
class ExampleParentClass
|
4
7
|
def == other
|
@@ -50,6 +53,7 @@ class ClassWithAttribs < ExampleParentClass
|
|
50
53
|
end
|
51
54
|
|
52
55
|
class Watchful
|
56
|
+
include Aquarium::Aspects::DSL::AspectDSL
|
53
57
|
class WatchfulError < Exception
|
54
58
|
def initialize message = nil
|
55
59
|
super
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
require 'aquarium/utils/method_utils'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Aquarium::Utils::MethodUtils, ".method_args_to_hash" do
|
5
5
|
|
6
6
|
it "should return an empty hash for no arguments." do
|
7
7
|
Aquarium::Utils::MethodUtils.method_args_to_hash().should == {}
|
@@ -47,4 +47,127 @@ describe "Aquarium::Utils::MethodUtils.method_args_to_hash" do
|
|
47
47
|
Aquarium::Utils::MethodUtils.method_args_to_hash(:x, :y, :a =>'a', :b => 'b'){|a| a.to_s.capitalize}.should == {:a => 'a', :b => 'b', :x => 'X', :y => 'Y'}
|
48
48
|
end
|
49
49
|
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Aquarium::Utils::MethodUtils, ".visibility" do
|
53
|
+
class ProtectionExample
|
54
|
+
def public_instance_m; end
|
55
|
+
protected
|
56
|
+
def protected_instance_m; end
|
57
|
+
private
|
58
|
+
def private_instance_m; end
|
59
|
+
def self.public_class_m; end
|
60
|
+
def self.private_class_m; end
|
61
|
+
private_class_method :private_class_m
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return :public for public class methods on a class" do
|
65
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m).should == :public
|
66
|
+
end
|
67
|
+
it "should return :public for public class methods on a class when only class methods are specified" do
|
68
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m, :class_method_only).should == :public
|
69
|
+
end
|
70
|
+
it "should return nil for public class methods on a class when only instance methods are specified" do
|
71
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m, :instance_method_only).should == nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return :public for public instance methods on a class" do
|
75
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m).should == :public
|
76
|
+
end
|
77
|
+
it "should return nil for public instance methods on a class when only class methods are specified" do
|
78
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m, :class_method_only).should == nil
|
79
|
+
end
|
80
|
+
it "should return :public for public instance methods on a class when only instance methods are specified" do
|
81
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m, :instance_method_only).should == :public
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return nil for public class methods on an instance of a class" do
|
85
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m).should == nil
|
86
|
+
end
|
87
|
+
it "should return nil for public class methods on an instance of a class when only class methods are specified" do
|
88
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m, :class_method_only).should == nil
|
89
|
+
end
|
90
|
+
it "should return nil for public class methods on an instance of a class when only instance methods are specified" do
|
91
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m, :instance_method_only).should == nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return :public for public instance methods on an instance of a class" do
|
95
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m).should == :public
|
96
|
+
end
|
97
|
+
it "should return nil for public instance methods on an instance of a class when only class methods are specified" do
|
98
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m, :class_method_only).should == nil
|
99
|
+
end
|
100
|
+
it "should return :public for public instance methods on an instance of a class when only instance methods are specified" do
|
101
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m, :instance_method_only).should == :public
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return :protected for protected instance methods on a class" do
|
105
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m).should == :protected
|
106
|
+
end
|
107
|
+
it "should return nil for protected instance methods on a class when only class methods are specified" do
|
108
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m, :class_method_only).should == nil
|
109
|
+
end
|
110
|
+
it "should return :protected for protected instance methods on a class when only instance methods are specified" do
|
111
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m, :instance_method_only).should == :protected
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return :protected for protected instance methods on an instance of a class" do
|
115
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m).should == :protected
|
116
|
+
end
|
117
|
+
it "should return nil for protected instance methods on an instance of a class when only class methods are specified" do
|
118
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m, :class_method_only).should == nil
|
119
|
+
end
|
120
|
+
it "should return :protected for protected instance methods on an instance of a class when only instance methods are specified" do
|
121
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m, :instance_method_only).should == :protected
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return :private for private class methods on a class" do
|
125
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m).should == :private #expected_private
|
126
|
+
end
|
127
|
+
it "should return :private for private class methods on a class when only class methods are specified" do
|
128
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m, :class_method_only).should == :private #expected_private
|
129
|
+
end
|
130
|
+
it "should return nil for private class methods on a class when only instance methods are specified" do
|
131
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m, :instance_method_only).should == nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return :private for private instance methods on a class" do
|
135
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m).should == :private
|
136
|
+
end
|
137
|
+
it "should return nil for private instance methods on a class when only class methods are specified" do
|
138
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m, :class_method_only).should == nil
|
139
|
+
end
|
140
|
+
it "should return :private for private instance methods on a class when only instance methods are specified" do
|
141
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m, :instance_method_only).should == :private
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return nil for private class methods on an instance of a class" do
|
145
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m).should == nil
|
146
|
+
end
|
147
|
+
it "should return nil for private class methods on an instance of a class when only class methods are specified" do
|
148
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m, :class_method_only).should == nil
|
149
|
+
end
|
150
|
+
it "should return nil for private class methods on an instance of a class when only instance methods are specified" do
|
151
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m, :instance_method_only).should == nil
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return :private for private instance methods on an instance of a class" do
|
155
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m).should == :private
|
156
|
+
end
|
157
|
+
it "should return nil for private instance methods on an instance of a class when only class methods are specified" do
|
158
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m, :class_method_only).should == nil
|
159
|
+
end
|
160
|
+
it "should return :private for private instance methods on an instance of a class when only instance methods are specified" do
|
161
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m, :instance_method_only).should == :private
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return nil for an unknown method" do
|
165
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method).should == nil
|
166
|
+
end
|
167
|
+
it "should return nil for an unknown method when only class methods are specified" do
|
168
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method, :class_method_only).should == nil
|
169
|
+
end
|
170
|
+
it "should return nil for an unknown method when only instance methods are specified" do
|
171
|
+
Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method, :instance_method_only).should == nil
|
172
|
+
end
|
50
173
|
end
|