aquarium 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +18 -0
- data/README +68 -39
- data/RELEASE-PLAN +25 -1
- data/UPGRADE +4 -0
- data/examples/aspect_design_example.rb +9 -3
- data/examples/aspect_design_example_spec.rb +7 -2
- data/examples/method_tracing_example.rb +1 -1
- data/examples/method_tracing_example_spec.rb +2 -2
- data/lib/aquarium/aspects/aspect.rb +53 -60
- data/lib/aquarium/aspects/dsl/aspect_dsl.rb +0 -1
- data/lib/aquarium/aspects/pointcut.rb +72 -17
- data/lib/aquarium/aspects/pointcut_composition.rb +4 -1
- data/lib/aquarium/extensions/hash.rb +65 -28
- data/lib/aquarium/extensions/set.rb +2 -0
- data/lib/aquarium/finders/finder_result.rb +13 -2
- data/lib/aquarium/finders/method_finder.rb +54 -28
- data/lib/aquarium/finders/type_finder.rb +36 -19
- data/lib/aquarium/utils/method_utils.rb +3 -12
- data/lib/aquarium/utils/name_utils.rb +27 -1
- data/lib/aquarium/version.rb +1 -1
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +182 -51
- data/spec/aquarium/aspects/aspect_spec.rb +43 -8
- data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +32 -3
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +36 -5
- data/spec/aquarium/aspects/pointcut_spec.rb +373 -99
- data/spec/aquarium/extensions/hash_spec.rb +129 -38
- data/spec/aquarium/finders/finder_result_spec.rb +73 -15
- data/spec/aquarium/finders/method_finder_spec.rb +156 -72
- data/spec/aquarium/finders/object_finder_spec.rb +1 -0
- data/spec/aquarium/finders/type_finder_spec.rb +43 -0
- data/spec/aquarium/utils/name_utils_spec.rb +79 -4
- metadata +3 -3
@@ -416,27 +416,27 @@ describe Aspect, "#new modifications to the list of methods for the advised obje
|
|
416
416
|
|
417
417
|
it "should not include new public instance or class methods for the advised type." do
|
418
418
|
all_public_methods_before = all_public_methods_of_type Watchful
|
419
|
-
@aspect = Aspect.new :after, :pointcut => {:type => Watchful, :method_options => :
|
419
|
+
@aspect = Aspect.new :after, :pointcut => {:type => Watchful, :method_options => :exclude_ancestor_methods}, :advice => @advice
|
420
420
|
(all_public_methods_of_type(Watchful) - all_public_methods_before).should == []
|
421
421
|
end
|
422
422
|
|
423
423
|
it "should not include new protected instance or class methods for the advised type." do
|
424
424
|
all_protected_methods_before = all_protected_methods_of_type Watchful
|
425
|
-
@aspect = Aspect.new :after, :pointcut => {:type => Watchful, :method_options => :
|
425
|
+
@aspect = Aspect.new :after, :pointcut => {:type => Watchful, :method_options => :exclude_ancestor_methods}, :advice => @advice
|
426
426
|
(all_protected_methods_of_type(Watchful) - all_protected_methods_before).should == []
|
427
427
|
end
|
428
428
|
|
429
429
|
it "should not include new public methods for the advised object." do
|
430
430
|
watchful = Watchful.new
|
431
431
|
all_public_methods_before = all_public_methods_of_object Watchful
|
432
|
-
@aspect = Aspect.new :after, :pointcut => {:object => watchful, :method_options => :
|
432
|
+
@aspect = Aspect.new :after, :pointcut => {:object => watchful, :method_options => :exclude_ancestor_methods}, :advice => @advice
|
433
433
|
(all_public_methods_of_object(Watchful) - all_public_methods_before).should == []
|
434
434
|
end
|
435
435
|
|
436
436
|
it "should not include new protected methods for the advised object." do
|
437
437
|
watchful = Watchful.new
|
438
438
|
all_protected_methods_before = all_protected_methods_of_object Watchful
|
439
|
-
@aspect = Aspect.new :after, :pointcut => {:object => watchful, :method_options => :
|
439
|
+
@aspect = Aspect.new :after, :pointcut => {:object => watchful, :method_options => :exclude_ancestor_methods}, :advice => @advice
|
440
440
|
(all_protected_methods_of_object(Watchful) - all_protected_methods_before).should == []
|
441
441
|
end
|
442
442
|
end
|
@@ -808,7 +808,7 @@ describe Aspect, "#new with :around advice" do
|
|
808
808
|
module AdvisingSuperClass
|
809
809
|
class SuperClass
|
810
810
|
def public_method *args
|
811
|
-
yield *args if block_given?
|
811
|
+
# yield *args if block_given?
|
812
812
|
end
|
813
813
|
protected
|
814
814
|
def protected_method *args
|
@@ -848,7 +848,7 @@ describe Aspect, "#new with :around advice" do
|
|
848
848
|
module AdvisingSubClass
|
849
849
|
class SuperClass
|
850
850
|
def public_method *args
|
851
|
-
yield *args if block_given?
|
851
|
+
# yield *args if block_given?
|
852
852
|
end
|
853
853
|
protected
|
854
854
|
def protected_method *args
|
@@ -1005,7 +1005,7 @@ describe Aspect, "#unadvise" do
|
|
1005
1005
|
|
1006
1006
|
it "should remove all advice added by the aspect." do
|
1007
1007
|
advice_called = false
|
1008
|
-
aspect = Aspect.new(:after, :pointcut => {:type => Watchful, :method_options => :
|
1008
|
+
aspect = Aspect.new(:after, :pointcut => {:type => Watchful, :method_options => :exclude_ancestor_methods}) {|jp, *args| advice_called = true}
|
1009
1009
|
aspect.unadvise
|
1010
1010
|
watchful = Watchful.new
|
1011
1011
|
|
@@ -1023,7 +1023,7 @@ describe Aspect, "#unadvise" do
|
|
1023
1023
|
def bar; end
|
1024
1024
|
end
|
1025
1025
|
before = Foo.private_instance_methods.sort
|
1026
|
-
aspect = Aspect.new(:after, :pointcut => {:type => Foo, :method_options => :
|
1026
|
+
aspect = Aspect.new(:after, :pointcut => {:type => Foo, :method_options => :exclude_ancestor_methods}) {|jp, *args| true}
|
1027
1027
|
after = Foo.private_instance_methods
|
1028
1028
|
(after - before).should_not == []
|
1029
1029
|
aspect.unadvise
|
@@ -1053,6 +1053,41 @@ describe Aspect, "Unadvising methods should restore the original protection leve
|
|
1053
1053
|
it_should_behave_like("invariant protection level of methods under advising and unadvising")
|
1054
1054
|
end
|
1055
1055
|
|
1056
|
+
|
1057
|
+
describe Aspect, "Advising methods with non-alphanumeric characters" do
|
1058
|
+
module Aquarium::Aspects
|
1059
|
+
class ClassWithMethodNamesContainingOddChars
|
1060
|
+
@@method_names = []
|
1061
|
+
%w[= ! ?].each do |s|
|
1062
|
+
@@method_names << "_a#{s}" << "a#{s}"
|
1063
|
+
end
|
1064
|
+
%w[+ - * / < << > >> =~ == === <=> % ^ ~ [] & | `].each do |s|
|
1065
|
+
@@method_names << s
|
1066
|
+
end
|
1067
|
+
@@method_names.each do |s|
|
1068
|
+
class_eval <<-EOF
|
1069
|
+
def #{s}; "#{s}"; end
|
1070
|
+
EOF
|
1071
|
+
end
|
1072
|
+
def self.method_names; @@method_names; end
|
1073
|
+
end
|
1074
|
+
end
|
1075
|
+
it "should work with any valid ruby character" do
|
1076
|
+
actual = ""
|
1077
|
+
Aspect.new :before, :type => Aquarium::Aspects::ClassWithMethodNamesContainingOddChars,
|
1078
|
+
:methods => Aquarium::Aspects::ClassWithMethodNamesContainingOddChars.method_names do |jp, *args|
|
1079
|
+
actual += ", #{jp.method_name}"
|
1080
|
+
end
|
1081
|
+
object = Aquarium::Aspects::ClassWithMethodNamesContainingOddChars.new
|
1082
|
+
expected = ""
|
1083
|
+
Aquarium::Aspects::ClassWithMethodNamesContainingOddChars.method_names.each do |s|
|
1084
|
+
object.send s
|
1085
|
+
expected += ", #{s}"
|
1086
|
+
end
|
1087
|
+
actual.should == expected
|
1088
|
+
end
|
1089
|
+
end
|
1090
|
+
|
1056
1091
|
describe Aspect, "#eql?" do
|
1057
1092
|
before(:all) do
|
1058
1093
|
@advice = Proc.new {}
|
@@ -5,9 +5,9 @@ require 'aquarium/extensions'
|
|
5
5
|
require 'aquarium/aspects/pointcut'
|
6
6
|
require 'aquarium/aspects/pointcut_composition'
|
7
7
|
|
8
|
-
describe "
|
8
|
+
describe "Intersection of Pointcuts", :shared => true do
|
9
9
|
include Aquarium::Utils::HashUtils
|
10
|
-
include Aquarium::Utils::HtmlEscaper
|
10
|
+
# include Aquarium::Utils::HtmlEscaper
|
11
11
|
|
12
12
|
before(:each) do
|
13
13
|
@example_types = {}
|
@@ -127,5 +127,34 @@ describe "Aquarium::Aspects::Pointcut#and" do
|
|
127
127
|
pc123b = pc1.and(pc2.and(pc3))
|
128
128
|
pc123a.should == pc123b
|
129
129
|
end
|
130
|
-
|
130
|
+
end
|
131
|
+
|
132
|
+
describe Aquarium::Aspects::Pointcut, "#and" do
|
133
|
+
it_should_behave_like "Intersection of Pointcuts"
|
134
|
+
end
|
135
|
+
|
136
|
+
describe Aquarium::Aspects::Pointcut, "#&" do
|
137
|
+
include Aquarium::Utils::HashUtils
|
138
|
+
|
139
|
+
it_should_behave_like "Intersection of Pointcuts"
|
140
|
+
|
141
|
+
it "should be associativity for type-based Aquarium::Aspects::Pointcuts." do
|
142
|
+
pc1 = Aquarium::Aspects::Pointcut.new :types => ClassWithAttribs, :attributes => [/^attr/], :attribute_options => [:writers]
|
143
|
+
pc2 = Aquarium::Aspects::Pointcut.new :types => ClassWithAttribs, :attributes => [/^attr/], :attribute_options => [:readers]
|
144
|
+
pc3 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/
|
145
|
+
pc123a = (pc1 & pc2) & pc3
|
146
|
+
pc123b = pc1 & (pc2 & pc3)
|
147
|
+
pc123a.should == pc123b
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should be associativity for object-based Aquarium::Aspects::Pointcuts." do
|
151
|
+
cwa = ClassWithAttribs.new
|
152
|
+
pub = ClassWithPublicInstanceMethod.new
|
153
|
+
pc1 = Aquarium::Aspects::Pointcut.new :objects => cwa, :attributes => [/^attr/], :attribute_options => [:writers]
|
154
|
+
pc2 = Aquarium::Aspects::Pointcut.new :objects => cwa, :attributes => [/^attr/], :attribute_options => [:readers]
|
155
|
+
pc3 = Aquarium::Aspects::Pointcut.new :objects => pub
|
156
|
+
pc123a = (pc1 & pc2) & pc3
|
157
|
+
pc123b = pc1 & (pc2 & pc3)
|
158
|
+
pc123a.should == pc123b
|
159
|
+
end
|
131
160
|
end
|
@@ -5,7 +5,7 @@ require 'aquarium/extensions'
|
|
5
5
|
require 'aquarium/aspects/pointcut'
|
6
6
|
require 'aquarium/aspects/pointcut_composition'
|
7
7
|
|
8
|
-
describe "
|
8
|
+
describe "Union of Pointcuts", :shared => true do
|
9
9
|
include Aquarium::Utils::HashUtils
|
10
10
|
|
11
11
|
before(:each) do
|
@@ -31,9 +31,9 @@ describe "Aquarium::Aspects::Pointcut#and" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should return a new Aquarium::Aspects::Pointcut whose join points are the union of the left- and right-hand side Aquarium::Aspects::Pointcuts for type-based Aquarium::Aspects::Pointcuts." do
|
34
|
-
pc1 = Aquarium::Aspects::Pointcut.new :types => ClassWithAttribs, :attributes => [/^attr/], :attribute_options => [:writers, :
|
34
|
+
pc1 = Aquarium::Aspects::Pointcut.new :types => ClassWithAttribs, :attributes => [/^attr/], :attribute_options => [:writers, :exclude_ancestor_methods]
|
35
35
|
# "[^F]" excludes the ClassWithFunkyMethodNames...
|
36
|
-
pc2 = Aquarium::Aspects::Pointcut.new :types => /Class[^F]+Method/, :method_options => :
|
36
|
+
pc2 = Aquarium::Aspects::Pointcut.new :types => /Class[^F]+Method/, :method_options => :exclude_ancestor_methods
|
37
37
|
pc = pc1.or pc2
|
38
38
|
jp1 = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method => :attrRW_ClassWithAttribs=
|
39
39
|
jp2 = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method => :attrW_ClassWithAttribs=
|
@@ -46,8 +46,8 @@ describe "Aquarium::Aspects::Pointcut#and" do
|
|
46
46
|
it "should return a new Aquarium::Aspects::Pointcut whose join points are the union of the left- and right-hand side Aquarium::Aspects::Pointcuts for object-based Aquarium::Aspects::Pointcuts." do
|
47
47
|
cwa = ClassWithAttribs.new
|
48
48
|
pub = ClassWithPublicInstanceMethod.new
|
49
|
-
pc1 = Aquarium::Aspects::Pointcut.new :objects => [cwa], :attributes => [/^attr/], :attribute_options => [:writers, :
|
50
|
-
pc2 = Aquarium::Aspects::Pointcut.new :object => pub, :method_options => :
|
49
|
+
pc1 = Aquarium::Aspects::Pointcut.new :objects => [cwa], :attributes => [/^attr/], :attribute_options => [:writers, :exclude_ancestor_methods]
|
50
|
+
pc2 = Aquarium::Aspects::Pointcut.new :object => pub, :method_options => :exclude_ancestor_methods
|
51
51
|
pc = pc1.or pc2
|
52
52
|
jp1 = Aquarium::Aspects::JoinPoint.new :object => cwa, :method => :attrRW_ClassWithAttribs=
|
53
53
|
jp2 = Aquarium::Aspects::JoinPoint.new :object => cwa, :method => :attrW_ClassWithAttribs=
|
@@ -110,4 +110,35 @@ describe "Aquarium::Aspects::Pointcut#and" do
|
|
110
110
|
pc123b = pc1.or(pc2.or(pc3))
|
111
111
|
pc123a.should eql(pc123b)
|
112
112
|
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Aquarium::Aspects::Pointcut, "#or" do
|
117
|
+
it_should_behave_like "Union of Pointcuts"
|
118
|
+
end
|
119
|
+
|
120
|
+
describe Aquarium::Aspects::Pointcut, "#|" do
|
121
|
+
include Aquarium::Utils::HashUtils
|
122
|
+
|
123
|
+
it_should_behave_like "Union of Pointcuts"
|
124
|
+
|
125
|
+
it "should be associativity for type-based Aquarium::Aspects::Pointcuts." do
|
126
|
+
pc1 = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/], :attribute_options => [:writers]
|
127
|
+
pc2 = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/], :attribute_options => [:readers]
|
128
|
+
pc3 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/
|
129
|
+
pc123a = (pc1 | pc2) | pc3
|
130
|
+
pc123b = pc1 | (pc2 | pc3)
|
131
|
+
pc123a.should eql(pc123b)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should be associativity for object-based Aquarium::Aspects::Pointcuts." do
|
135
|
+
cwa = ClassWithAttribs.new
|
136
|
+
pub = ClassWithPublicInstanceMethod.new
|
137
|
+
pc1 = Aquarium::Aspects::Pointcut.new :objects => cwa, :attributes => [/^attr/], :attribute_options => [:writers]
|
138
|
+
pc2 = Aquarium::Aspects::Pointcut.new :objects => cwa, :attributes => [/^attr/], :attribute_options => [:readers]
|
139
|
+
pc3 = Aquarium::Aspects::Pointcut.new :objects => pub
|
140
|
+
pc123a = (pc1 | pc2) | pc3
|
141
|
+
pc123b = pc1 | (pc2 | pc3)
|
142
|
+
pc123a.should eql(pc123b)
|
143
|
+
end
|
113
144
|
end
|
@@ -6,7 +6,50 @@ require 'aquarium/aspects/join_point'
|
|
6
6
|
require 'aquarium/aspects/pointcut'
|
7
7
|
require 'aquarium/utils'
|
8
8
|
|
9
|
-
|
9
|
+
class ExcludeTestOne
|
10
|
+
def method11; end
|
11
|
+
def method12; end
|
12
|
+
def method13; end
|
13
|
+
end
|
14
|
+
class ExcludeTestTwo
|
15
|
+
def method21; end
|
16
|
+
def method22; end
|
17
|
+
def method23; end
|
18
|
+
end
|
19
|
+
class ExcludeTestThree
|
20
|
+
def method31; end
|
21
|
+
def method32; end
|
22
|
+
def method33; end
|
23
|
+
end
|
24
|
+
|
25
|
+
def before_exclude_spec
|
26
|
+
@jp11 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method11
|
27
|
+
@jp12 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method12
|
28
|
+
@jp13 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method13
|
29
|
+
@jp21 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestTwo, :method_name => :method21
|
30
|
+
@jp22 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestTwo, :method_name => :method22
|
31
|
+
@jp23 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestTwo, :method_name => :method23
|
32
|
+
@jp31 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestThree, :method_name => :method31
|
33
|
+
@jp32 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestThree, :method_name => :method32
|
34
|
+
@jp33 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestThree, :method_name => :method33
|
35
|
+
@et1 = ExcludeTestOne.new
|
36
|
+
@et2 = ExcludeTestTwo.new
|
37
|
+
@et3 = ExcludeTestThree.new
|
38
|
+
@ojp11 = Aquarium::Aspects::JoinPoint.new :object => @et1, :method_name => :method11
|
39
|
+
@ojp12 = Aquarium::Aspects::JoinPoint.new :object => @et1, :method_name => :method12
|
40
|
+
@ojp13 = Aquarium::Aspects::JoinPoint.new :object => @et1, :method_name => :method13
|
41
|
+
@ojp21 = Aquarium::Aspects::JoinPoint.new :object => @et2, :method_name => :method21
|
42
|
+
@ojp22 = Aquarium::Aspects::JoinPoint.new :object => @et2, :method_name => :method22
|
43
|
+
@ojp23 = Aquarium::Aspects::JoinPoint.new :object => @et2, :method_name => :method23
|
44
|
+
@ojp31 = Aquarium::Aspects::JoinPoint.new :object => @et3, :method_name => :method31
|
45
|
+
@ojp32 = Aquarium::Aspects::JoinPoint.new :object => @et3, :method_name => :method32
|
46
|
+
@ojp33 = Aquarium::Aspects::JoinPoint.new :object => @et3, :method_name => :method33
|
47
|
+
@all_type_jps = [@jp11, @jp12, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @jp33]
|
48
|
+
@all_object_jps = [@ojp11, @ojp12, @ojp13, @ojp21, @ojp22, @ojp23, @ojp31, @ojp32, @ojp33]
|
49
|
+
@all_jps = @all_type_jps + @all_object_jps
|
50
|
+
end
|
51
|
+
|
52
|
+
def before_pointcut_spec
|
10
53
|
@example_types_without_public_instance_method =
|
11
54
|
[ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod, ClassWithPublicClassMethod, ClassWithPrivateClassMethod]
|
12
55
|
@example_types = ([ClassWithPublicInstanceMethod] + @example_types_without_public_instance_method)
|
@@ -95,75 +138,75 @@ describe Aquarium::Aspects::Pointcut, "#empty?" do
|
|
95
138
|
end
|
96
139
|
|
97
140
|
describe Aquarium::Aspects::Pointcut, " (types specified using regular expressions)" do
|
98
|
-
|
99
|
-
|
141
|
+
before(:each) do
|
142
|
+
before_pointcut_spec
|
100
143
|
end
|
101
144
|
|
102
|
-
it "should match multiple
|
103
|
-
pc = Aquarium::Aspects::Pointcut.new :types => /Class.*Method\Z/, :method_options => :
|
145
|
+
it "should match multiple types using regular expressions that cover the full class names." do
|
146
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /Class.*Method\Z/, :method_options => :exclude_ancestor_methods
|
104
147
|
pc.join_points_matched.should == @expected_matched_jps
|
105
148
|
pc.join_points_not_matched.should == @expected_not_matched_jps
|
106
149
|
end
|
107
150
|
|
108
|
-
it "should match
|
109
|
-
pc = Aquarium::Aspects::Pointcut.new :types => /lass.*Pro.*Inst.*Met/, :method_options => [:public, :protected, :
|
151
|
+
it "should match types using regular expressions that only cover partial class names." do
|
152
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /lass.*Pro.*Inst.*Met/, :method_options => [:public, :protected, :exclude_ancestor_methods]
|
110
153
|
pc.join_points_matched.should == Set.new([@pro_jp])
|
111
154
|
pc.join_points_not_matched.size.should == 0
|
112
155
|
end
|
113
156
|
end
|
114
157
|
|
115
158
|
describe Aquarium::Aspects::Pointcut, " (types specified using names)" do
|
116
|
-
|
117
|
-
|
159
|
+
before(:each) do
|
160
|
+
before_pointcut_spec
|
118
161
|
end
|
119
162
|
|
120
|
-
it "should match multiple
|
121
|
-
pc = Aquarium::Aspects::Pointcut.new :types => @example_types.map {|t| t.to_s}, :method_options => :
|
163
|
+
it "should match multiple types using names." do
|
164
|
+
pc = Aquarium::Aspects::Pointcut.new :types => @example_types.map {|t| t.to_s}, :method_options => :exclude_ancestor_methods
|
122
165
|
pc.join_points_matched.should == @expected_matched_jps
|
123
166
|
pc.join_points_not_matched.should == @expected_not_matched_jps
|
124
167
|
end
|
125
168
|
|
126
|
-
it "should match multiple
|
127
|
-
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :
|
169
|
+
it "should match multiple types using types themselves." do
|
170
|
+
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :exclude_ancestor_methods
|
128
171
|
pc.join_points_matched.should == @expected_matched_jps
|
129
172
|
pc.join_points_not_matched.should == @expected_not_matched_jps
|
130
173
|
end
|
131
174
|
|
132
175
|
it "should match :all public instance methods for types by default." do
|
133
|
-
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :
|
176
|
+
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :exclude_ancestor_methods
|
134
177
|
pc.join_points_matched.should == @expected_matched_jps
|
135
178
|
pc.join_points_not_matched.should == @expected_not_matched_jps
|
136
179
|
end
|
137
180
|
|
138
|
-
it "should support MethodFinder's :
|
139
|
-
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :
|
181
|
+
it "should support MethodFinder's :exclude_ancestor_methods option when using types." do
|
182
|
+
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :method_options => :exclude_ancestor_methods
|
140
183
|
pc.join_points_matched.should == @expected_matched_jps
|
141
184
|
pc.join_points_not_matched.should == @expected_not_matched_jps
|
142
185
|
end
|
143
186
|
end
|
144
187
|
|
145
188
|
describe Aquarium::Aspects::Pointcut, " (objects specified)" do
|
146
|
-
|
147
|
-
|
189
|
+
before(:each) do
|
190
|
+
before_pointcut_spec
|
148
191
|
end
|
149
192
|
|
150
193
|
it "should match :all public instance methods for objects by default." do
|
151
194
|
pub, pro = ClassWithPublicInstanceMethod.new, ClassWithProtectedInstanceMethod.new
|
152
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :method_options => :
|
195
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :method_options => :exclude_ancestor_methods
|
153
196
|
pc.join_points_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :public_instance_test_method)])
|
154
197
|
pc.join_points_not_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:object => pro, :method_name => :all)])
|
155
198
|
end
|
156
199
|
|
157
|
-
it "should support MethodFinder's :
|
200
|
+
it "should support MethodFinder's :exclude_ancestor_methods option when using objects." do
|
158
201
|
pub, pro = ClassWithPublicInstanceMethod.new, ClassWithProtectedInstanceMethod.new
|
159
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :method_options => :
|
202
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :method_options => :exclude_ancestor_methods
|
160
203
|
pc.join_points_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :public_instance_test_method)])
|
161
204
|
pc.join_points_not_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:object => pro, :method_name => :all)])
|
162
205
|
end
|
163
206
|
|
164
207
|
it "should match all possible methods on the specified objects." do
|
165
208
|
pub, pro = ClassWithPublicInstanceMethod.new, ClassWithProtectedInstanceMethod.new
|
166
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :methods => :all, :method_options => [:public, :protected, :
|
209
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [pub, pro], :methods => :all, :method_options => [:public, :protected, :exclude_ancestor_methods]
|
167
210
|
pc.join_points_matched.size.should == 2
|
168
211
|
pc.join_points_not_matched.size.should == 0
|
169
212
|
pc.join_points_matched.should == Set.new([
|
@@ -182,105 +225,290 @@ describe Aquarium::Aspects::Pointcut, " (objects specified)" do
|
|
182
225
|
end
|
183
226
|
end
|
184
227
|
|
228
|
+
describe Aquarium::Aspects::Pointcut, " (:exclude_types => types specified)" do
|
229
|
+
before(:each) do
|
230
|
+
before_exclude_spec
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should remove from a list of explicitly-specified types the set of explicitly-specified excluded types." do
|
234
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [ExcludeTestOne, ExcludeTestTwo, ExcludeTestThree], :exclude_type => ExcludeTestTwo, :method_options => :exclude_ancestor_methods
|
235
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
236
|
+
actual.size.should == 2
|
237
|
+
actual.should include(ExcludeTestOne)
|
238
|
+
actual.should include(ExcludeTestThree)
|
239
|
+
pc.join_points_not_matched.size.should == 0
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should remove from a list of explicitly-specified types the set of excluded types specified by regular expression." do
|
243
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [ExcludeTestOne, ExcludeTestTwo, ExcludeTestThree], :exclude_types => /Two$/, :method_options => :exclude_ancestor_methods
|
244
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
245
|
+
actual.size.should == 2
|
246
|
+
actual.should include(ExcludeTestOne)
|
247
|
+
actual.should include(ExcludeTestThree)
|
248
|
+
pc.join_points_not_matched.size.should == 0
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should remove from a list of explicitly-specified types the set of excluded types specified by name." do
|
252
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [ExcludeTestOne, ExcludeTestTwo, ExcludeTestThree], :exclude_type => "ExcludeTestTwo", :method_options => :exclude_ancestor_methods
|
253
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
254
|
+
actual.size.should == 2
|
255
|
+
actual.should include(ExcludeTestOne)
|
256
|
+
actual.should include(ExcludeTestThree)
|
257
|
+
pc.join_points_not_matched.size.should == 0
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should remove from the types specified by regular expression the explicitly-specified excluded types." do
|
261
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_type => ExcludeTestTwo, :method_options => :exclude_ancestor_methods
|
262
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
263
|
+
actual.size.should == 2
|
264
|
+
actual.should include(ExcludeTestOne)
|
265
|
+
actual.should include(ExcludeTestThree)
|
266
|
+
pc.join_points_not_matched.size.should == 0
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should remove from the types specified by regular expression the excluded types specified by regular expression." do
|
270
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_type => /Two$/, :method_options => :exclude_ancestor_methods
|
271
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
272
|
+
actual.size.should == 2
|
273
|
+
actual.should include(ExcludeTestOne)
|
274
|
+
actual.should include(ExcludeTestThree)
|
275
|
+
pc.join_points_not_matched.size.should == 0
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should remove from the types specified by regular expression the excluded types specified by name." do
|
279
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_type => "ExcludeTestTwo", :method_options => :exclude_ancestor_methods
|
280
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
281
|
+
actual.size.should == 2
|
282
|
+
actual.should include(ExcludeTestOne)
|
283
|
+
actual.should include(ExcludeTestThree)
|
284
|
+
pc.join_points_not_matched.size.should == 0
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should remove from the join points corresponding to the excluded types, specified by name." do
|
288
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_type_jps, :exclude_type => "ExcludeTestTwo", :method_options => :exclude_ancestor_methods
|
289
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
290
|
+
actual.size.should == 2
|
291
|
+
actual.should include(ExcludeTestOne)
|
292
|
+
actual.should include(ExcludeTestThree)
|
293
|
+
pc.join_points_not_matched.size.should == 0
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should remove the specified join points corresponding to the excluded types, specified by regular expression." do
|
297
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_type_jps, :exclude_type => /Exclude.*Two/, :method_options => :exclude_ancestor_methods
|
298
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
299
|
+
actual.size.should == 2
|
300
|
+
actual.should include(ExcludeTestOne)
|
301
|
+
actual.should include(ExcludeTestThree)
|
302
|
+
pc.join_points_not_matched.size.should == 0
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should not add excluded types to the #not_matched results." do
|
306
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_type => ExcludeTestTwo, :method_options => :exclude_ancestor_methods
|
307
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
308
|
+
pc.join_points_not_matched.size.should == 0
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should be a synonym for :exclude_type." do
|
312
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_types => [ExcludeTestTwo, ExcludeTestThree], :method_options => :exclude_ancestor_methods
|
313
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
314
|
+
actual.size.should == 1
|
315
|
+
actual.should include(ExcludeTestOne)
|
316
|
+
pc.join_points_not_matched.size.should == 0
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe Aquarium::Aspects::Pointcut, " (:exclude_objects => objects specified)" do
|
321
|
+
before(:each) do
|
322
|
+
@e11 = ExcludeTestOne.new
|
323
|
+
@e12 = ExcludeTestOne.new
|
324
|
+
@e21 = ExcludeTestTwo.new
|
325
|
+
@e22 = ExcludeTestTwo.new
|
326
|
+
@e31 = ExcludeTestThree.new
|
327
|
+
@e32 = ExcludeTestThree.new
|
328
|
+
@objects = [@e11, @e12, @e21, @e22, @e31, @e32]
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should remove from the matched objects the excluded objects." do
|
332
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => @objects, :exclude_objects => [@e22, @e31], :method_options => :exclude_ancestor_methods
|
333
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
334
|
+
actual.size.should == 4
|
335
|
+
[@e11, @e12, @e21, @e32].each {|e| actual.should include(e)}
|
336
|
+
pc.join_points_not_matched.size.should == 0
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should remove the specified join points corresponding to the excluded objects." do
|
340
|
+
jps11 = Aquarium::Aspects::JoinPoint.new :object => @e11, :method => :method11
|
341
|
+
jps21 = Aquarium::Aspects::JoinPoint.new :object => @e21, :method => :method21
|
342
|
+
jps22 = Aquarium::Aspects::JoinPoint.new :object => @e22, :method => :method22
|
343
|
+
jps31 = Aquarium::Aspects::JoinPoint.new :object => @e31, :method => :method31
|
344
|
+
jps = [jps11, jps21, jps22, jps31]
|
345
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => jps, :exclude_objects => [@e22, @e31], :method_options => :exclude_ancestor_methods
|
346
|
+
pc.join_points_matched.size.should == 2
|
347
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
348
|
+
[@e11, @e21].each {|e| actual.should include(e)}
|
349
|
+
pc.join_points_not_matched.size.should == 0
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should not add excluded objects to the #not_matched results." do
|
353
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => @objects, :exclude_objects => [@e22, @e31], :method_options => :exclude_ancestor_methods
|
354
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
355
|
+
pc.join_points_not_matched.size.should == 0
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should be a synonym for :exclude_object." do
|
359
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => @objects, :exclude_object => @e22, :method_options => :exclude_ancestor_methods
|
360
|
+
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
361
|
+
actual.size.should == 5
|
362
|
+
[@e11, @e12, @e21, @e31, @e32].each {|e| actual.should include(e)}
|
363
|
+
pc.join_points_not_matched.size.should == 0
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe Aquarium::Aspects::Pointcut, " (:exclude_join_points => join_points specified)" do
|
368
|
+
before(:each) do
|
369
|
+
before_exclude_spec
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should remove from a list of explicitly-specified join points the set of explicitly-specified excluded join points." do
|
373
|
+
excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
|
374
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_join_points => excluded
|
375
|
+
pc.join_points_matched.should == Set.new(@all_jps - excluded)
|
376
|
+
pc.join_points_not_matched.size.should == 0
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should remove from the list of generated, type-based join points the set of explicitly-specified excluded join points." do
|
380
|
+
jp11 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method11
|
381
|
+
jp22 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestTwo, :method_name => :method22
|
382
|
+
jp33 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestThree, :method_name => :method33
|
383
|
+
excluded = [jp11, jp22, jp33]
|
384
|
+
pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_join_points => excluded, :method_options => :exclude_ancestor_methods
|
385
|
+
pc.join_points_matched.should == Set.new(@all_type_jps - excluded)
|
386
|
+
pc.join_points_not_matched.size.should == 0
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should remove from the list of generated, object-based join points the set of explicitly-specified excluded join points." do
|
390
|
+
ojp12 = Aquarium::Aspects::JoinPoint.new :object => @et1, :method_name => :method12
|
391
|
+
ojp23 = Aquarium::Aspects::JoinPoint.new :object => @et2, :method_name => :method23
|
392
|
+
ojp31 = Aquarium::Aspects::JoinPoint.new :object => @et3, :method_name => :method31
|
393
|
+
excluded = [ojp12, ojp23, ojp31]
|
394
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [@et1, @et2, @et3], :exclude_join_points => excluded, :method_options => :exclude_ancestor_methods
|
395
|
+
pc.join_points_matched.should == Set.new(@all_object_jps - excluded)
|
396
|
+
pc.join_points_not_matched.size.should == 0
|
397
|
+
end
|
398
|
+
|
399
|
+
it "should not add excluded types to the #not_matched results." do
|
400
|
+
excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
|
401
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_join_points => excluded
|
402
|
+
pc.join_points_not_matched.size.should == 0
|
403
|
+
end
|
404
|
+
|
405
|
+
it "should be a synonym for :exclude_join_point." do
|
406
|
+
excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
|
407
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_join_point => excluded
|
408
|
+
pc.join_points_matched.should == Set.new(@all_jps - excluded)
|
409
|
+
pc.join_points_not_matched.size.should == 0
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
185
413
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with public instance methods)" do
|
186
|
-
|
187
|
-
|
414
|
+
before(:each) do
|
415
|
+
before_pointcut_spec
|
188
416
|
end
|
189
417
|
|
190
418
|
it "should support MethodFinder's :public and :instance options for the specified types." do
|
191
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPublicInstanceMethod, :method_options => [:public, :instance, :
|
192
|
-
pc.join_points_matched.should
|
419
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPublicInstanceMethod, :method_options => [:public, :instance, :exclude_ancestor_methods]
|
420
|
+
pc.join_points_matched.should be_eql(Set.new([@pub_jp]))
|
193
421
|
pc.join_points_not_matched.size.should == 0
|
194
422
|
end
|
195
423
|
|
196
424
|
it "should support MethodFinder's :public and :instance options for the specified objects." do
|
197
425
|
pub = ClassWithPublicInstanceMethod.new
|
198
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => pub, :method_options => [:public, :instance, :
|
199
|
-
pc.join_points_matched.should
|
426
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => pub, :method_options => [:public, :instance, :exclude_ancestor_methods]
|
427
|
+
pc.join_points_matched.should be_eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :public_instance_test_method)]))
|
200
428
|
pc.join_points_not_matched.size.should == 0
|
201
429
|
end
|
202
430
|
end
|
203
431
|
|
204
432
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with protected instance methods)" do
|
205
|
-
|
206
|
-
|
433
|
+
before(:each) do
|
434
|
+
before_pointcut_spec
|
207
435
|
end
|
208
436
|
|
209
437
|
it "should support MethodFinder's :protected and :instance options for the specified types." do
|
210
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithProtectedInstanceMethod, :method_options => [:protected, :instance, :
|
211
|
-
pc.join_points_matched.should
|
438
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithProtectedInstanceMethod, :method_options => [:protected, :instance, :exclude_ancestor_methods]
|
439
|
+
pc.join_points_matched.should be_eql(Set.new([@pro_jp]))
|
212
440
|
pc.join_points_not_matched.size.should == 0
|
213
441
|
end
|
214
442
|
|
215
443
|
it "should support MethodFinder's :protected and :instance options for the specified objects." do
|
216
444
|
pro = ClassWithProtectedInstanceMethod.new
|
217
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => pro, :method_options => [:protected, :instance, :
|
218
|
-
pc.join_points_matched.should
|
445
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => pro, :method_options => [:protected, :instance, :exclude_ancestor_methods]
|
446
|
+
pc.join_points_matched.should be_eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pro, :method_name => :protected_instance_test_method)]))
|
219
447
|
pc.join_points_not_matched.size.should == 0
|
220
448
|
end
|
221
449
|
end
|
222
450
|
|
223
451
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with private instance methods)" do
|
224
|
-
|
225
|
-
|
452
|
+
before(:each) do
|
453
|
+
before_pointcut_spec
|
226
454
|
end
|
227
455
|
|
228
456
|
it "should support MethodFinder's :private and :instance options for the specified types." do
|
229
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPrivateInstanceMethod, :method_options => [:private, :instance, :
|
230
|
-
pc.join_points_matched.should
|
457
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPrivateInstanceMethod, :method_options => [:private, :instance, :exclude_ancestor_methods]
|
458
|
+
pc.join_points_matched.should be_eql(Set.new([@pri_jp]))
|
231
459
|
pc.join_points_not_matched.size.should == 0
|
232
460
|
end
|
233
461
|
|
234
462
|
it "should support MethodFinder's :private and :instance options for the specified objects." do
|
235
463
|
pro = ClassWithPrivateInstanceMethod.new
|
236
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => pro, :method_options => [:private, :instance, :
|
237
|
-
pc.join_points_matched.should
|
464
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => pro, :method_options => [:private, :instance, :exclude_ancestor_methods]
|
465
|
+
pc.join_points_matched.should be_eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pro, :method_name => :private_instance_test_method)]))
|
238
466
|
pc.join_points_not_matched.size.should == 0
|
239
467
|
end
|
240
468
|
end
|
241
469
|
|
242
470
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with public class methods)" do
|
243
|
-
|
244
|
-
|
471
|
+
before(:each) do
|
472
|
+
before_pointcut_spec
|
245
473
|
end
|
246
474
|
|
247
475
|
it "should support MethodFinder's :public and :class options for the specified types." do
|
248
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPublicClassMethod, :method_options => [:public, :class, :
|
249
|
-
pc.join_points_matched.should
|
476
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPublicClassMethod, :method_options => [:public, :class, :exclude_ancestor_methods]
|
477
|
+
pc.join_points_matched.should be_eql(Set.new([@cpub_jp]))
|
250
478
|
pc.join_points_not_matched.size.should == 0
|
251
479
|
end
|
252
480
|
|
253
481
|
it "should support MethodFinder's :public and :class options for the specified objects, which will return no methods." do
|
254
482
|
pub = ClassWithPublicInstanceMethod.new
|
255
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => pub, :method_options => [:public, :class, :
|
483
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => pub, :method_options => [:public, :class, :exclude_ancestor_methods]
|
256
484
|
pc.join_points_matched.size.should == 0
|
257
485
|
pc.join_points_not_matched.size.should == 1
|
258
|
-
pc.join_points_not_matched.should
|
486
|
+
pc.join_points_not_matched.should be_eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pub, :method_name => :all, :class_method => true)]))
|
259
487
|
end
|
260
488
|
end
|
261
489
|
|
262
490
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with private class methods)" do
|
263
|
-
|
264
|
-
|
491
|
+
before(:each) do
|
492
|
+
before_pointcut_spec
|
265
493
|
end
|
266
494
|
|
267
495
|
it "should support MethodFinder's :private and :class options for the specified types." do
|
268
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPrivateClassMethod, :method_options => [:private, :class, :
|
269
|
-
pc.join_points_matched.should
|
496
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithPrivateClassMethod, :method_options => [:private, :class, :exclude_ancestor_methods]
|
497
|
+
pc.join_points_matched.should be_eql(Set.new([@cpri_jp]))
|
270
498
|
pc.join_points_not_matched.size.should == 0
|
271
499
|
end
|
272
500
|
|
273
501
|
it "should support MethodFinder's :private and :class options for the specified objects, which will return no methods." do
|
274
502
|
pri = ClassWithPrivateInstanceMethod.new
|
275
|
-
pc = Aquarium::Aspects::Pointcut.new :objects => pri, :method_options => [:private, :class, :
|
276
|
-
pc.join_points_not_matched.should
|
503
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => pri, :method_options => [:private, :class, :exclude_ancestor_methods]
|
504
|
+
pc.join_points_not_matched.should be_eql(Set.new([Aquarium::Aspects::JoinPoint.new(:object => pri, :method_name => :all, :class_method => true)]))
|
277
505
|
pc.join_points_not_matched.size.should == 1
|
278
506
|
end
|
279
507
|
end
|
280
508
|
|
281
509
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with method regular expressions)" do
|
282
|
-
|
283
|
-
|
510
|
+
before(:each) do
|
511
|
+
before_pointcut_spec
|
284
512
|
@jp_rwe = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrRW_ClassWithAttribs=
|
285
513
|
@jp_rw = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrRW_ClassWithAttribs
|
286
514
|
@jp_we = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrW_ClassWithAttribs=
|
@@ -310,9 +538,57 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with method
|
|
310
538
|
end
|
311
539
|
end
|
312
540
|
|
541
|
+
describe Aquarium::Aspects::Pointcut, " (:exclude_methods => methods specified)" do
|
542
|
+
before(:each) do
|
543
|
+
before_exclude_spec
|
544
|
+
end
|
545
|
+
|
546
|
+
it "should remove type-specified JoinPoints matching the excluded methods specified by name." do
|
547
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [ExcludeTestOne, ExcludeTestTwo, ExcludeTestThree], :exclude_methods => [:method11, :method23], :method_options => :exclude_ancestor_methods
|
548
|
+
pc.join_points_matched.size.should == 7
|
549
|
+
pc.join_points_matched.should == Set.new([@jp12, @jp13, @jp21, @jp22, @jp31, @jp32, @jp33])
|
550
|
+
pc.join_points_not_matched.size.should == 0
|
551
|
+
end
|
552
|
+
|
553
|
+
it "should remove type-specified JoinPoints matching the excluded methods specified by regular expression." do
|
554
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [ExcludeTestOne, ExcludeTestTwo, ExcludeTestThree], :exclude_methods => /method[12][13]/, :method_options => :exclude_ancestor_methods
|
555
|
+
pc.join_points_matched.size.should == 5
|
556
|
+
pc.join_points_matched.should == Set.new([@jp12, @jp22, @jp31, @jp32, @jp33])
|
557
|
+
pc.join_points_not_matched.size.should == 0
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should remove object-specified JoinPoints matching the excluded methods specified by name." do
|
561
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [@et1, @et2, @et3], :exclude_methods => [:method11, :method23], :method_options => :exclude_ancestor_methods
|
562
|
+
pc.join_points_matched.size.should == 7
|
563
|
+
pc.join_points_matched.should == Set.new([@ojp12, @ojp13, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33])
|
564
|
+
pc.join_points_not_matched.size.should == 0
|
565
|
+
end
|
566
|
+
|
567
|
+
it "should remove object-specified JoinPoints matching the excluded methods specified by regular expression." do
|
568
|
+
pc = Aquarium::Aspects::Pointcut.new :objects => [@et1, @et2, @et3], :exclude_methods => /method[12][13]/, :method_options => :exclude_ancestor_methods
|
569
|
+
pc.join_points_matched.size.should == 5
|
570
|
+
pc.join_points_matched.should == Set.new([@ojp12, @ojp22, @ojp31, @ojp32, @ojp33])
|
571
|
+
pc.join_points_not_matched.size.should == 0
|
572
|
+
end
|
573
|
+
|
574
|
+
it "should remove join-point-specified JoinPoints matching the excluded methods specified by name." do
|
575
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_methods => [:method11, :method23], :method_options => :exclude_ancestor_methods
|
576
|
+
pc.join_points_matched.size.should == 14
|
577
|
+
pc.join_points_matched.should == Set.new([@jp12, @jp13, @jp21, @jp22, @jp31, @jp32, @jp33, @ojp12, @ojp13, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33])
|
578
|
+
pc.join_points_not_matched.size.should == 0
|
579
|
+
end
|
580
|
+
|
581
|
+
it "should remove join-point-specified JoinPoints matching the excluded methods specified by regular expression." do
|
582
|
+
pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_methods => /method[12][13]/, :method_options => :exclude_ancestor_methods
|
583
|
+
pc.join_points_matched.size.should == 10
|
584
|
+
pc.join_points_matched.should == Set.new([@jp12, @jp22, @jp31, @jp32, @jp33, @ojp12, @ojp22, @ojp31, @ojp32, @ojp33])
|
585
|
+
pc.join_points_not_matched.size.should == 0
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
313
589
|
describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribute regular expressions)" do
|
314
|
-
|
315
|
-
|
590
|
+
before(:each) do
|
591
|
+
before_pointcut_spec
|
316
592
|
@jp_rwe = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrRW_ClassWithAttribs=
|
317
593
|
@jp_rw = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrRW_ClassWithAttribs
|
318
594
|
@jp_we = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttribs, :method_name => :attrW_ClassWithAttribs=
|
@@ -328,6 +604,7 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
328
604
|
|
329
605
|
it "should match on public attribute readers and writers for type names by default." do
|
330
606
|
pc = Aquarium::Aspects::Pointcut.new :types => "ClassWithAttribs", :attributes => [/^attr/]
|
607
|
+
pc.join_points_matched.size.should == 4
|
331
608
|
pc.join_points_matched.should == @expected_for_types
|
332
609
|
end
|
333
610
|
|
@@ -463,8 +740,8 @@ describe Aquarium::Aspects::Pointcut, " (types or objects specified with attribu
|
|
463
740
|
end
|
464
741
|
|
465
742
|
describe Aquarium::Aspects::Pointcut, " (join points specified)" do
|
466
|
-
|
467
|
-
|
743
|
+
before(:each) do
|
744
|
+
before_pointcut_spec
|
468
745
|
@anClassWithPublicInstanceMethod = ClassWithPublicInstanceMethod.new
|
469
746
|
@expected_matched = [@pub_jp, @pro_jp, @pri_jp, @cpub_jp, @cpri_jp,
|
470
747
|
Aquarium::Aspects::JoinPoint.new(:object => @anClassWithPublicInstanceMethod, :method => :public_instance_test_method)]
|
@@ -506,25 +783,25 @@ describe Aquarium::Aspects::Pointcut, " (methods that end in non-alphanumeric ch
|
|
506
783
|
|
507
784
|
{'?' => :huh?, '!' => :yes!, '=' => :x=}.each do |char, method|
|
508
785
|
it "should match instance methods for types when searching for names that end with a '#{char}' character." do
|
509
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithFunkyMethodNames, :method => method, :method_options => [:
|
786
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithFunkyMethodNames, :method => method, :method_options => [:exclude_ancestor_methods]
|
510
787
|
expected_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithFunkyMethodNames, :method_name => method
|
511
788
|
pc.join_points_matched.should == Set.new([expected_jp])
|
512
789
|
end
|
513
790
|
|
514
791
|
it "should match instance methods for objects when searching for names that end with a '#{char}' character." do
|
515
|
-
pc = Aquarium::Aspects::Pointcut.new :object => @funky, :method => method, :method_options => [:
|
792
|
+
pc = Aquarium::Aspects::Pointcut.new :object => @funky, :method => method, :method_options => [:exclude_ancestor_methods]
|
516
793
|
expected_jp = Aquarium::Aspects::JoinPoint.new :object => @funky, :method_name => method
|
517
794
|
pc.join_points_matched.should == Set.new([expected_jp])
|
518
795
|
end
|
519
796
|
|
520
797
|
it "should match instance methods for types when searching for names that end with a '#{char}' character, using a regular expressions." do
|
521
|
-
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithFunkyMethodNames, :methods => /#{Regexp.escape(char)}$/, :method_options => [:
|
798
|
+
pc = Aquarium::Aspects::Pointcut.new :types => ClassWithFunkyMethodNames, :methods => /#{Regexp.escape(char)}$/, :method_options => [:exclude_ancestor_methods]
|
522
799
|
expected_jp = Aquarium::Aspects::JoinPoint.new :type => ClassWithFunkyMethodNames, :method_name => method
|
523
800
|
pc.join_points_matched.should == Set.new([expected_jp])
|
524
801
|
end
|
525
802
|
|
526
803
|
it "should match instance methods for object when searching for names that end with a '#{char}' character, using a regular expressions." do
|
527
|
-
pc = Aquarium::Aspects::Pointcut.new :object => @funky, :methods => /#{Regexp.escape(char)}$/, :method_options => [:
|
804
|
+
pc = Aquarium::Aspects::Pointcut.new :object => @funky, :methods => /#{Regexp.escape(char)}$/, :method_options => [:exclude_ancestor_methods]
|
528
805
|
expected_jp = Aquarium::Aspects::JoinPoint.new :object => @funky, :method_name => method
|
529
806
|
pc.join_points_matched.should == Set.new([expected_jp])
|
530
807
|
end
|
@@ -568,7 +845,7 @@ end
|
|
568
845
|
|
569
846
|
describe "Aquarium::Aspects::Pointcut" do
|
570
847
|
|
571
|
-
|
848
|
+
before(:each) do
|
572
849
|
class Empty; end
|
573
850
|
|
574
851
|
@objectWithSingletonMethod = Empty.new
|
@@ -593,7 +870,7 @@ describe "Aquarium::Aspects::Pointcut" do
|
|
593
870
|
end
|
594
871
|
|
595
872
|
it "should find type-level singleton methods for types when :singleton is specified." do
|
596
|
-
pc = Aquarium::Aspects::Pointcut.new :types => [NotQuiteEmpty, Empty], :methods => :all, :method_options => [:singleton, :
|
873
|
+
pc = Aquarium::Aspects::Pointcut.new :types => [NotQuiteEmpty, Empty], :methods => :all, :method_options => [:singleton, :exclude_ancestor_methods]
|
597
874
|
pc.join_points_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:type => NotQuiteEmpty, :method_name => :a_class_singleton_method)])
|
598
875
|
pc.join_points_not_matched.should == Set.new([Aquarium::Aspects::JoinPoint.new(:type => Empty, :method_name => :all)])
|
599
876
|
end
|
@@ -610,15 +887,15 @@ end
|
|
610
887
|
describe Aquarium::Aspects::Pointcut, "#eql?" do
|
611
888
|
it "should return true for the same Aquarium::Aspects::Pointcut object." do
|
612
889
|
pc = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/, :methods => /_test_method$/
|
613
|
-
pc.should
|
890
|
+
pc.should be_eql(pc)
|
614
891
|
pc1 = Aquarium::Aspects::Pointcut.new :object => ClassWithPublicClassMethod.new, :methods => /_test_method$/
|
615
|
-
pc1.should
|
892
|
+
pc1.should be_eql(pc1)
|
616
893
|
end
|
617
894
|
|
618
895
|
it "should return true for Aquarium::Aspects::Pointcuts that specify the same types and methods." do
|
619
896
|
pc1 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/, :methods => /_test_method$/
|
620
897
|
pc2 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/, :methods => /_test_method$/
|
621
|
-
pc1.should
|
898
|
+
pc1.should be_eql(pc2)
|
622
899
|
end
|
623
900
|
|
624
901
|
it "should return false for Aquarium::Aspects::Pointcuts that specify different types." do
|
@@ -731,16 +1008,16 @@ describe "Aquarium::Aspects::Pointcut#eql?" do
|
|
731
1008
|
pc1 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/, :methods => /_test_method$/
|
732
1009
|
pc2 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/, :methods => /_test_method$/
|
733
1010
|
pc3 = Aquarium::Aspects::Pointcut.new :objects => [ClassWithPublicInstanceMethod.new, ClassWithPublicInstanceMethod.new]
|
734
|
-
pc1.should
|
735
|
-
pc1.should
|
1011
|
+
pc1.should be_eql(pc1)
|
1012
|
+
pc1.should be_eql(pc2)
|
736
1013
|
pc1.should_not eql(pc3)
|
737
1014
|
pc2.should_not eql(pc3)
|
738
1015
|
end
|
739
1016
|
end
|
740
1017
|
|
741
1018
|
describe Aquarium::Aspects::Pointcut, "#candidate_types" do
|
742
|
-
|
743
|
-
|
1019
|
+
before(:each) do
|
1020
|
+
before_pointcut_spec
|
744
1021
|
end
|
745
1022
|
|
746
1023
|
it "should return only candidate matching types when the input types exist." do
|
@@ -769,8 +1046,8 @@ describe Aquarium::Aspects::Pointcut, "#candidate_types" do
|
|
769
1046
|
end
|
770
1047
|
|
771
1048
|
describe Aquarium::Aspects::Pointcut, "#candidate_objects" do
|
772
|
-
|
773
|
-
|
1049
|
+
before(:each) do
|
1050
|
+
before_pointcut_spec
|
774
1051
|
end
|
775
1052
|
|
776
1053
|
it "should return only candidate matching objects when the input are objects." do
|
@@ -784,8 +1061,8 @@ describe Aquarium::Aspects::Pointcut, "#candidate_objects" do
|
|
784
1061
|
end
|
785
1062
|
|
786
1063
|
describe Aquarium::Aspects::Pointcut, "#candidate_join_points" do
|
787
|
-
|
788
|
-
|
1064
|
+
before(:each) do
|
1065
|
+
before_pointcut_spec
|
789
1066
|
end
|
790
1067
|
|
791
1068
|
it "should return only candidate non-matching join points for the input join points that do not exist." do
|
@@ -813,63 +1090,60 @@ describe Aquarium::Aspects::Pointcut, "#candidate_join_points" do
|
|
813
1090
|
end
|
814
1091
|
|
815
1092
|
describe Aquarium::Aspects::Pointcut, "#specification" do
|
816
|
-
|
817
|
-
|
818
|
-
@expected_specification_subset = {
|
819
|
-
:methods => [:all], :method_options => [:suppress_ancestor_methods],
|
820
|
-
:attributes => [], :attribute_options => []}
|
1093
|
+
before(:each) do
|
1094
|
+
before_pointcut_spec
|
821
1095
|
@empty_set = Set.new
|
1096
|
+
@default_specification = {
|
1097
|
+
:types => @empty_set, :objects => @empty_set, :join_points => @empty_set,
|
1098
|
+
:methods => @empty_set, :method_options => @empty_set,
|
1099
|
+
:attributes => @empty_set, :attribute_options => @empty_set,
|
1100
|
+
:exclude_types => @empty_set,
|
1101
|
+
:exclude_objects => @empty_set,
|
1102
|
+
:exclude_join_points => @empty_set,
|
1103
|
+
:exclude_methods => @empty_set,
|
1104
|
+
:default_object => @empty_set}
|
1105
|
+
@default_specification_all_methods = { :methods => Set.new([:all]) } | @default_specification
|
822
1106
|
end
|
823
1107
|
|
824
1108
|
it "should return ':attribute_options => []', by default, if no arguments are given." do
|
825
1109
|
pc = Aquarium::Aspects::Pointcut.new
|
826
|
-
pc.specification.should ==
|
827
|
-
:methods => Set.new([:all]), :method_options => Set.new([]), :default_object => @empty_set,
|
828
|
-
:attributes => @empty_set, :attribute_options => @empty_set }
|
1110
|
+
pc.specification.should == @default_specification_all_methods
|
829
1111
|
end
|
830
1112
|
|
831
1113
|
it "should return the input :types and :type arguments combined into an array keyed by :types." do
|
832
1114
|
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :type => String
|
833
|
-
pc.specification.should == { :types => Set.new(@example_types + [String])
|
834
|
-
:methods => Set.new([:all]), :method_options => Set.new([]), :default_object => @empty_set,
|
835
|
-
:attributes => @empty_set, :attribute_options => @empty_set }
|
1115
|
+
pc.specification.should == { :types => Set.new(@example_types + [String]) } | @default_specification_all_methods
|
836
1116
|
end
|
837
1117
|
|
838
1118
|
it "should return the input :objects and :object arguments combined into an array keyed by :objects." do
|
839
1119
|
example_objs = @example_types.map {|t| t.new}
|
840
1120
|
s1234 = "1234"
|
841
1121
|
pc = Aquarium::Aspects::Pointcut.new :objects => example_objs, :object => s1234
|
842
|
-
pc.specification.should == { :
|
843
|
-
:methods => Set.new([:all]), :method_options => Set.new([]), :default_object => @empty_set,
|
844
|
-
:attributes => @empty_set, :attribute_options => @empty_set }
|
1122
|
+
pc.specification.should == { :objects => Set.new(example_objs + [s1234]) } | @default_specification_all_methods
|
845
1123
|
end
|
846
1124
|
|
847
1125
|
it "should return the input :methods and :method arguments combined into an array keyed by :methods." do
|
848
1126
|
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :methods => /^get/, :method => "dup"
|
849
|
-
pc.specification.should == { :types => Set.new(@example_types), :
|
850
|
-
:methods => Set.new([/^get/, "dup"]), :method_options => Set.new([]), :default_object => @empty_set,
|
851
|
-
:attributes => @empty_set, :attribute_options => @empty_set }
|
1127
|
+
pc.specification.should == { :types => Set.new(@example_types), :methods => Set.new([/^get/, "dup"]) } | @default_specification
|
852
1128
|
end
|
853
1129
|
|
854
1130
|
it "should return the input :method_options verbatim." do
|
855
1131
|
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :methods => /^get/, :method => "dup", :method_options => [:instance, :public]
|
856
|
-
pc.specification.should == { :types => Set.new(@example_types), :
|
857
|
-
|
858
|
-
:attributes => @empty_set, :attribute_options => @empty_set }
|
1132
|
+
pc.specification.should == { :types => Set.new(@example_types), :methods => Set.new([/^get/, "dup"]),
|
1133
|
+
:method_options => Set.new([:instance, :public]), :default_object => @empty_set } | @default_specification
|
859
1134
|
end
|
860
1135
|
|
861
1136
|
it "should return the input :methods and :method arguments combined into an array keyed by :methods." do
|
862
1137
|
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :attributes => /^state/, :attribute => "name"
|
863
1138
|
pc.specification.should == { :types => Set.new(@example_types), :objects => @empty_set, :join_points => @empty_set,
|
864
1139
|
:methods => @empty_set, :method_options => Set.new([]), :default_object => @empty_set,
|
865
|
-
:attributes => Set.new([/^state/, "name"]), :attribute_options => @empty_set }
|
1140
|
+
:attributes => Set.new([/^state/, "name"]), :attribute_options => @empty_set } | @default_specification
|
866
1141
|
end
|
867
1142
|
|
868
1143
|
it "should return the input :attributes, :attribute and :attribute_options arguments, verbatim." do
|
869
1144
|
pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :attributes => /^state/, :attribute => "name", :attribute_options => :reader
|
870
|
-
pc.specification.should == { :types => Set.new(@example_types), :
|
871
|
-
:
|
872
|
-
:attributes => Set.new([/^state/, "name"]), :attribute_options => Set.new([:reader]) }
|
1145
|
+
pc.specification.should == { :types => Set.new(@example_types), :attributes => Set.new([/^state/, "name"]),
|
1146
|
+
:attribute_options => Set.new([:reader]) } | @default_specification
|
873
1147
|
end
|
874
1148
|
end
|
875
1149
|
|