aquarium 0.1.8 → 0.2.0
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 +59 -2
- data/README +33 -16
- data/RELEASE-PLAN +28 -5
- data/UPGRADE +11 -0
- data/examples/aspect_design_example.rb +2 -2
- data/examples/aspect_design_example_spec.rb +2 -2
- data/examples/design_by_contract_example.rb +4 -4
- data/examples/design_by_contract_example_spec.rb +4 -4
- data/examples/method_missing_example.rb +4 -1
- data/examples/method_missing_example_spec.rb +4 -1
- data/examples/method_tracing_example.rb +2 -2
- data/examples/method_tracing_example_spec.rb +16 -16
- data/lib/aquarium/aspects/advice.rb +47 -25
- data/lib/aquarium/aspects/aspect.rb +81 -39
- data/lib/aquarium/aspects/dsl/aspect_dsl.rb +1 -1
- data/lib/aquarium/aspects/exclusion_handler.rb +2 -2
- data/lib/aquarium/aspects/join_point.rb +28 -28
- data/lib/aquarium/aspects/pointcut.rb +61 -15
- data/lib/aquarium/extras/design_by_contract.rb +7 -7
- data/lib/aquarium/finders.rb +0 -1
- data/lib/aquarium/finders/method_finder.rb +10 -20
- data/lib/aquarium/finders/type_finder.rb +141 -75
- data/lib/aquarium/utils.rb +1 -0
- data/lib/aquarium/utils/logic_error.rb +9 -0
- data/lib/aquarium/utils/method_utils.rb +4 -3
- data/lib/aquarium/utils/nil_object.rb +1 -0
- data/lib/aquarium/utils/type_utils.rb +19 -0
- data/lib/aquarium/version.rb +2 -2
- data/spec/aquarium/aspects/advice_chain_node_spec.rb +2 -2
- data/spec/aquarium/aspects/advice_spec.rb +28 -5
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +522 -289
- data/spec/aquarium/aspects/aspect_spec.rb +59 -41
- data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +7 -7
- data/spec/aquarium/aspects/aspect_with_subtypes_spec.rb +2 -2
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +1 -2
- data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +1 -1
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +34 -34
- data/spec/aquarium/aspects/join_point_spec.rb +79 -0
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +13 -3
- data/spec/aquarium/aspects/pointcut_spec.rb +310 -63
- data/spec/aquarium/extras/design_by_contract_spec.rb +4 -4
- data/spec/aquarium/finders/method_finder_spec.rb +208 -54
- data/spec/aquarium/finders/type_finder_spec.rb +24 -88
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +206 -0
- data/spec/aquarium/spec_example_classes.rb +75 -12
- data/spec/aquarium/utils/logic_error_spec.rb +10 -0
- data/spec/aquarium/utils/type_utils_sample_classes.rb +203 -0
- data/spec/aquarium/utils/type_utils_spec.rb +47 -1
- metadata +48 -39
- data/lib/aquarium/finders/object_finder.rb +0 -75
- data/spec/aquarium/finders/object_finder_spec.rb +0 -231
data/lib/aquarium/utils.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'aquarium/utils/type_utils'
|
2
|
+
require 'aquarium/utils/logic_error'
|
2
3
|
|
3
4
|
module Aquarium
|
4
5
|
module Utils
|
@@ -18,13 +19,13 @@ module Aquarium
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.visibility type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
|
21
|
-
find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |
|
22
|
+
find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
|
22
23
|
return protection
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.has_method type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
|
27
|
-
found = find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |
|
28
|
+
found = find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
|
28
29
|
return true
|
29
30
|
end
|
30
31
|
found ? true : false # found could be nil; return false, if so
|
@@ -69,7 +70,7 @@ module Aquarium
|
|
69
70
|
if candidates.size == 2 and Aquarium::Utils::TypeUtils.is_type?(type_or_instance) == false
|
70
71
|
return determine_actual_parent(type_or_instance, candidates)
|
71
72
|
end
|
72
|
-
candidates.size == 1 ? candidates.first : raise("Bug: Got multiple types #{candidates.inspect} that implement method #{method_sym}")
|
73
|
+
candidates.size == 1 ? candidates.first : raise(Aquarium::Utils::LogicError.new("Bug: Got multiple types #{candidates.inspect} that implement method #{method_sym}"))
|
73
74
|
end
|
74
75
|
|
75
76
|
def self.determine_actual_parent object, candidates
|
@@ -4,6 +4,25 @@ module Aquarium
|
|
4
4
|
def self.is_type? type_or_object
|
5
5
|
type_or_object.kind_of?(Class) or type_or_object.kind_of?(Module)
|
6
6
|
end
|
7
|
+
|
8
|
+
def self.descendents clazz
|
9
|
+
do_descendents clazz, Class, ["Class", "Module", "Object", clazz]
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def self.do_descendents clazz, class_with_consts, visited
|
15
|
+
result = [clazz]
|
16
|
+
visited << class_with_consts.name
|
17
|
+
class_with_consts.constants.each do |const|
|
18
|
+
next if const == clazz.name or visited.include?(const)
|
19
|
+
clazz2 = class_with_consts.class_eval "#{const}"
|
20
|
+
next unless clazz2.respond_to?(:ancestors)
|
21
|
+
result += [clazz2] if clazz2.ancestors.include? clazz
|
22
|
+
result += do_descendents(clazz, clazz2, visited) unless visited.include?(clazz2.name)
|
23
|
+
end
|
24
|
+
result.flatten.uniq
|
25
|
+
end
|
7
26
|
end
|
8
27
|
end
|
9
28
|
end
|
data/lib/aquarium/version.rb
CHANGED
@@ -9,7 +9,7 @@ include Aquarium::Aspects::Advice
|
|
9
9
|
describe Aquarium::Aspects::AdviceChainNode, "#each" do
|
10
10
|
it "should return each node in succession" do
|
11
11
|
static_join_point = :static_join_point
|
12
|
-
advice = lambda {|jp, *args| p ":none advice"}
|
12
|
+
advice = lambda {|jp, obj, *args| p ":none advice"}
|
13
13
|
options = {
|
14
14
|
:advice_kind => :none,
|
15
15
|
:advice => advice,
|
@@ -18,7 +18,7 @@ describe Aquarium::Aspects::AdviceChainNode, "#each" do
|
|
18
18
|
advice_chain = Aquarium::Aspects::AdviceChainNodeFactory.make_node options
|
19
19
|
|
20
20
|
KINDS_IN_PRIORITY_ORDER.each do |advice_kind|
|
21
|
-
advice = lambda {|jp, *args| p "#{advice_kind} advice"}
|
21
|
+
advice = lambda {|jp, obj, *args| p "#{advice_kind} advice"}
|
22
22
|
options[:advice_kind] = advice_kind
|
23
23
|
options[:advice] = advice,
|
24
24
|
options[:next_node] = advice_chain
|
@@ -18,9 +18,32 @@ describe Advice, "#sort_by_priority_order" do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
describe Advice, "#invoke_original_join_point" do
|
22
|
+
class InvocationCounter
|
23
|
+
def initialize; @counter = 0; end
|
24
|
+
def increment; @counter += 1; end
|
25
|
+
def counter; @counter; end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should invoke the original join_point" do
|
29
|
+
aspect1 = Aspect.new :before, :type => InvocationCounter, :method => :increment do |jp, o|
|
30
|
+
jp.invoke_original_join_point
|
31
|
+
end
|
32
|
+
aspect2 = Aspect.new :around, :type => InvocationCounter, :method => :increment do |jp, o|
|
33
|
+
jp.invoke_original_join_point
|
34
|
+
jp.proceed
|
35
|
+
end
|
36
|
+
ic = InvocationCounter.new
|
37
|
+
ic.increment
|
38
|
+
ic.counter == 3
|
39
|
+
aspect1.unadvise
|
40
|
+
aspect2.unadvise
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
21
44
|
describe Advice, "that raises an exception" do
|
22
45
|
it "should add the kind of advice to the exception message." do
|
23
|
-
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, *args|
|
46
|
+
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, obj, *args|
|
24
47
|
raise SpecExceptionForTesting.new("advice called with args: #{args.inspect}")
|
25
48
|
end
|
26
49
|
begin
|
@@ -32,7 +55,7 @@ describe Advice, "that raises an exception" do
|
|
32
55
|
end
|
33
56
|
|
34
57
|
it "should add the \"Class#method\" of the advised object's type and method to the exception message." do
|
35
|
-
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, *args|
|
58
|
+
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_watchful_method} do |jp, obj, *args|
|
36
59
|
raise "advice called with args: #{args.inspect}"
|
37
60
|
end
|
38
61
|
begin
|
@@ -44,7 +67,7 @@ describe Advice, "that raises an exception" do
|
|
44
67
|
end
|
45
68
|
|
46
69
|
it "should add the \"Class.method\" of the advised type's class method to the exception message." do
|
47
|
-
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, *args|
|
70
|
+
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args|
|
48
71
|
raise "advice called with args: #{args.inspect}"
|
49
72
|
end
|
50
73
|
begin
|
@@ -57,7 +80,7 @@ describe Advice, "that raises an exception" do
|
|
57
80
|
|
58
81
|
it "should rethrow an exception of the same type as the original exception." do
|
59
82
|
class MyException < Exception; end
|
60
|
-
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, *args|
|
83
|
+
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args|
|
61
84
|
raise MyException.new("advice called with args: #{args.inspect}")
|
62
85
|
end
|
63
86
|
lambda { Watchful.public_class_watchful_method :a1, :a2 }.should raise_error(MyException)
|
@@ -67,7 +90,7 @@ describe Advice, "that raises an exception" do
|
|
67
90
|
it "should rethrow an exception with the same backtrace as the original exception." do
|
68
91
|
class MyException < Exception; end
|
69
92
|
@backtrace = nil
|
70
|
-
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, *args|
|
93
|
+
aspect = Aspect.new :before, :pointcut => {:type => Watchful, :methods => :public_class_watchful_method, :method_options => [:class]} do |jp, obj, *args|
|
71
94
|
begin
|
72
95
|
exception = MyException.new("advice called with args: #{args.inspect}")
|
73
96
|
raise exception
|
@@ -29,114 +29,128 @@ def join_points_should_be_equal num_jps, aspect1, aspect2
|
|
29
29
|
aspect1.join_points_not_matched.should eql(aspect2.join_points_not_matched)
|
30
30
|
end
|
31
31
|
|
32
|
+
module Aquarium
|
33
|
+
class AspectInvocationTestClass
|
34
|
+
include Aquarium::Aspects::DSL::AspectDSL
|
35
|
+
attr_accessor :public_test_method_args
|
36
|
+
def public_test_method *args; @args=args; end
|
37
|
+
protected
|
38
|
+
def protected_test_method *args; @args=args; end
|
39
|
+
private
|
40
|
+
def private_test_method *args; @args=args; end
|
41
|
+
def self.public_class_test_method *args; end
|
42
|
+
def self.private_class_test_method *args; end
|
43
|
+
private_class_method :private_class_test_method
|
44
|
+
end
|
45
|
+
end
|
32
46
|
|
33
|
-
describe Aspect, "
|
47
|
+
describe Aspect, ".new parameters that specify the kind of advice" do
|
34
48
|
it "should require the kind of advice as the first parameter." do
|
35
|
-
lambda { Aspect.new :pointcut => {:type =>
|
49
|
+
lambda { Aspect.new :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
36
50
|
end
|
37
51
|
|
38
52
|
it "should contain no other advice types if :around advice specified." do
|
39
|
-
lambda { Aspect.new :around, :before, :pointcut => {:type =>
|
40
|
-
lambda { Aspect.new :around, :after, :pointcut => {:type =>
|
41
|
-
lambda { Aspect.new :around, :after_returning, :pointcut => {:type =>
|
42
|
-
lambda { Aspect.new :around, :after_raising, :pointcut => {:type =>
|
53
|
+
lambda { Aspect.new :around, :before, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
54
|
+
lambda { Aspect.new :around, :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
55
|
+
lambda { Aspect.new :around, :after_returning, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
56
|
+
lambda { Aspect.new :around, :after_raising, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
43
57
|
end
|
44
58
|
|
45
59
|
it "should allow only one of :after, :after_returning, or :after_raising advice to be specified." do
|
46
|
-
lambda { Aspect.new :after, :after_returning, :pointcut => {:type =>
|
47
|
-
lambda { Aspect.new :after, :after_raising, :pointcut => {:type =>
|
48
|
-
lambda { Aspect.new :after_returning, :after_raising, :pointcut => {:type =>
|
60
|
+
lambda { Aspect.new :after, :after_returning, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
61
|
+
lambda { Aspect.new :after, :after_raising, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
62
|
+
lambda { Aspect.new :after_returning, :after_raising, :pointcut => {:type => Aquarium::AspectInvocationTestClass} }.should raise_error(Aquarium::Utils::InvalidOptions)
|
49
63
|
end
|
50
64
|
|
51
65
|
it "should allow :before to be specified with :after." do
|
52
|
-
lambda { Aspect.new :before, :after, :pointcut => {:type =>
|
66
|
+
lambda { Aspect.new :before, :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass}, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
53
67
|
end
|
54
68
|
|
55
69
|
it "should allow :before to be specified with :after_returning." do
|
56
|
-
lambda { Aspect.new :before, :after_returning, :pointcut => {:type =>
|
70
|
+
lambda { Aspect.new :before, :after_returning, :pointcut => {:type => Aquarium::AspectInvocationTestClass}, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
57
71
|
end
|
58
72
|
|
59
73
|
it "should allow :before to be specified with :after_raising." do
|
60
|
-
lambda { Aspect.new :before, :after_raising, :pointcut => {:type =>
|
74
|
+
lambda { Aspect.new :before, :after_raising, :pointcut => {:type => Aquarium::AspectInvocationTestClass}, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
64
|
-
describe Aspect, "
|
78
|
+
describe Aspect, ".new parameters that specify join points" do
|
65
79
|
it "should contain at least one of :method(s), :pointcut(s), :type(s), or :object(s)." do
|
66
|
-
lambda {Aspect.new(:after) {|jp, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
80
|
+
lambda {Aspect.new(:after) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
67
81
|
end
|
68
82
|
|
69
83
|
it "should contain at least one of :pointcut(s), :type(s), or :object(s) unless :default_object => object is given." do
|
70
|
-
aspect = Aspect.new(:after, :default_object =>
|
84
|
+
aspect = Aspect.new(:after, :default_object => Aquarium::AspectInvocationTestClass.new, :methods => :public_test_method) {|jp, obj, *args| true}
|
71
85
|
aspect.unadvise
|
72
86
|
end
|
73
87
|
|
74
88
|
it "should not contain :pointcut(s) and either :type(s) or :object(s)." do
|
75
|
-
lambda {Aspect.new(:after, :pointcuts => {:type =>
|
76
|
-
lambda {Aspect.new(:after, :pointcuts => {:type =>
|
89
|
+
lambda {Aspect.new(:after, :pointcuts => {:type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method}, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
90
|
+
lambda {Aspect.new(:after, :pointcuts => {:type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method}, :object => Aquarium::AspectInvocationTestClass.new, :methods => :public_test_method) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
77
91
|
end
|
78
92
|
|
79
93
|
it "should include an advice block or :advice => advice parameter." do
|
80
|
-
lambda {Aspect.new(:after, :type =>
|
94
|
+
lambda {Aspect.new(:after, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method)}.should raise_error(Aquarium::Utils::InvalidOptions)
|
81
95
|
end
|
82
96
|
end
|
83
97
|
|
84
98
|
|
85
|
-
describe Aspect, "
|
99
|
+
describe Aspect, ".new :type parameter" do
|
86
100
|
it "should be accepted as a synonym for :types" do
|
87
101
|
@advice = Proc.new {}
|
88
|
-
@expected_methods = [:
|
89
|
-
aspect1 = Aspect.new :before, :type =>
|
90
|
-
aspect2 = Aspect.new :before, :types =>
|
102
|
+
@expected_methods = [:public_test_method]
|
103
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :method => @expected_methods, :advice => @advice
|
104
|
+
aspect2 = Aspect.new :before, :types => Aquarium::AspectInvocationTestClass, :method => @expected_methods, :advice => @advice
|
91
105
|
aspects_should_be_equal 1, aspect1, aspect2
|
92
106
|
aspect1.unadvise
|
93
107
|
aspect2.unadvise
|
94
108
|
end
|
95
109
|
end
|
96
110
|
|
97
|
-
describe Aspect, "
|
111
|
+
describe Aspect, ".new :pointcut parameter" do
|
98
112
|
it "should be accepted as a synonym for :pointcuts" do
|
99
113
|
@advice = Proc.new {}
|
100
|
-
@expected_methods = [:
|
101
|
-
aspect1 = Aspect.new :before, :pointcut => {:type =>
|
102
|
-
aspect2 = Aspect.new :before, :pointcuts => {:type =>
|
114
|
+
@expected_methods = [:public_test_method]
|
115
|
+
aspect1 = Aspect.new :before, :pointcut => {:type => Aquarium::AspectInvocationTestClass, :method => @expected_methods}, :advice => @advice
|
116
|
+
aspect2 = Aspect.new :before, :pointcuts => {:type => Aquarium::AspectInvocationTestClass, :method => @expected_methods}, :advice => @advice
|
103
117
|
aspects_should_be_equal 1, aspect1, aspect2
|
104
118
|
aspect1.unadvise
|
105
119
|
aspect2.unadvise
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
109
|
-
describe Aspect, "
|
123
|
+
describe Aspect, ".new :object parameter" do
|
110
124
|
it "should be accepted as a synonym for :objects" do
|
111
125
|
@advice = Proc.new {}
|
112
|
-
@expected_methods = [:
|
113
|
-
|
114
|
-
aspect1 = Aspect.new :before, :object =>
|
115
|
-
aspect2 = Aspect.new :before, :objects =>
|
126
|
+
@expected_methods = [:public_test_method]
|
127
|
+
object = Aquarium::AspectInvocationTestClass.new
|
128
|
+
aspect1 = Aspect.new :before, :object => object, :method => @expected_methods, :advice => @advice
|
129
|
+
aspect2 = Aspect.new :before, :objects => object, :method => @expected_methods, :advice => @advice
|
116
130
|
aspects_should_be_equal 1, aspect1, aspect2
|
117
131
|
aspect1.unadvise
|
118
132
|
aspect2.unadvise
|
119
133
|
end
|
120
134
|
end
|
121
135
|
|
122
|
-
describe Aspect, "
|
136
|
+
describe Aspect, ".new :method parameter" do
|
123
137
|
it "should be accepted as a synonym for :methods" do
|
124
138
|
@advice = Proc.new {}
|
125
|
-
@expected_methods = [:
|
126
|
-
aspect1 = Aspect.new :before, :type =>
|
127
|
-
aspect2 = Aspect.new :before, :type =>
|
139
|
+
@expected_methods = [:public_test_method]
|
140
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :method => @expected_methods, :advice => @advice
|
141
|
+
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => @expected_methods, :advice => @advice
|
128
142
|
aspects_should_be_equal 1, aspect1, aspect2
|
129
143
|
aspect1.unadvise
|
130
144
|
aspect2.unadvise
|
131
145
|
end
|
132
146
|
end
|
133
147
|
|
134
|
-
describe Aspect, "
|
148
|
+
describe Aspect, ".new :attribute parameter" do
|
135
149
|
it "should be accepted as a synonym for :attributes" do
|
136
150
|
@advice = Proc.new {}
|
137
|
-
@expected_methods = [:
|
138
|
-
aspect1 = Aspect.new :before, :type =>
|
139
|
-
aspect2 = Aspect.new :before, :type =>
|
151
|
+
@expected_methods = [:public_test_method_args, :public_test_method_args=]
|
152
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attribute => @expected_methods, :advice => @advice
|
153
|
+
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => @expected_methods, :advice => @advice
|
140
154
|
aspects_should_be_equal 2, aspect1, aspect2
|
141
155
|
aspect1.unadvise
|
142
156
|
aspect2.unadvise
|
@@ -144,103 +158,146 @@ describe Aspect, "#new :attribute parameter" do
|
|
144
158
|
end
|
145
159
|
|
146
160
|
|
147
|
-
describe Aspect, "
|
161
|
+
describe Aspect, ".new with a :type(s) parameter and a :method(s) parameter" do
|
148
162
|
before :each do
|
149
163
|
@protection = 'public'
|
150
164
|
@are_class_methods = false
|
165
|
+
@types_option = :types
|
151
166
|
@method_options = []
|
152
167
|
end
|
153
168
|
|
154
169
|
def do_type_spec
|
155
170
|
aspect = nil
|
156
171
|
advice_called = false
|
157
|
-
aspect = Aspect.new :before,
|
172
|
+
aspect = Aspect.new :before, @types_option => @type_spec, :methods => @method_spec, :method_options => @method_options do |jp, obj, *args|
|
158
173
|
advice_called = true
|
159
174
|
jp.should_not be_nil
|
160
175
|
args.size.should == 4
|
161
176
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
162
177
|
end
|
163
178
|
if @are_class_methods
|
164
|
-
|
179
|
+
Aquarium::AspectInvocationTestClass.method("#{@protection}_class_test_method").call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
165
180
|
else
|
166
|
-
|
181
|
+
Aquarium::AspectInvocationTestClass.new.method("#{@protection}_test_method").call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
167
182
|
end
|
168
183
|
advice_called.should be_true
|
169
184
|
aspect.unadvise
|
170
185
|
end
|
171
186
|
|
172
187
|
it "should accept :type(s) => [T1, ...], :methods => [m, ...]" do
|
173
|
-
@type_spec = [
|
174
|
-
@method_spec = [:
|
188
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
189
|
+
@method_spec = [:public_test_method]
|
190
|
+
do_type_spec
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should accept :type(s)_and_ancestors => [T1, ...], :methods => [m, ...]" do
|
194
|
+
@types_option = :types_and_ancestors
|
195
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
196
|
+
@method_spec = [:public_test_method]
|
197
|
+
do_type_spec
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should accept :type(s)_and_descendents => [T1, ...], :methods => [m, ...]" do
|
201
|
+
@types_option = :types_and_descendents
|
202
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
203
|
+
@method_spec = [:public_test_method]
|
175
204
|
do_type_spec
|
176
205
|
end
|
177
206
|
|
178
207
|
it "should accept :type(s) => [T1, ...], :methods => m" do
|
179
|
-
@type_spec = [
|
180
|
-
@method_spec = :
|
208
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
209
|
+
@method_spec = :public_test_method
|
181
210
|
do_type_spec
|
182
211
|
end
|
183
212
|
|
184
213
|
it "should accept :type(s) => [T1, ...], :methods => /m/" do
|
185
|
-
@type_spec = [
|
186
|
-
@method_spec = /
|
214
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
215
|
+
@method_spec = /test_method/
|
187
216
|
do_type_spec
|
188
217
|
end
|
189
218
|
|
190
219
|
it "should accept :type(s) => T1, :methods => [m, ...]" do
|
191
|
-
@type_spec =
|
192
|
-
@method_spec = [:
|
220
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
221
|
+
@method_spec = [:public_test_method]
|
222
|
+
do_type_spec
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should accept :type(s)_and_ancestors => T1, :methods => [m, ...]" do
|
226
|
+
@types_option = :types_and_ancestors
|
227
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
228
|
+
@method_spec = [:public_test_method]
|
229
|
+
do_type_spec
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should accept :type(s)_and_descendents => T1, :methods => [m, ...]" do
|
233
|
+
@types_option = :types_and_descendents
|
234
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
235
|
+
@method_spec = [:public_test_method]
|
193
236
|
do_type_spec
|
194
237
|
end
|
195
238
|
|
196
239
|
it "should accept :type(s) => T1, :methods => m" do
|
197
|
-
@type_spec =
|
198
|
-
@method_spec = :
|
240
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
241
|
+
@method_spec = :public_test_method
|
199
242
|
do_type_spec
|
200
243
|
end
|
201
244
|
|
202
245
|
it "should accept :type(s) => T1, :methods => /m/" do
|
203
|
-
@type_spec =
|
204
|
-
@method_spec = /
|
246
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
247
|
+
@method_spec = /test_method/
|
205
248
|
do_type_spec
|
206
249
|
end
|
207
250
|
|
208
251
|
it "should accept :type(s) => /T1/, :methods => [m, ...]" do
|
209
|
-
@type_spec = /
|
210
|
-
@method_spec = [:
|
252
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
253
|
+
@method_spec = [:public_test_method]
|
254
|
+
do_type_spec
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should accept :type(s)_and_ancestors => /T1/, :methods => [m, ...]" do
|
258
|
+
@types_option = :types_and_ancestors
|
259
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
260
|
+
@method_spec = [:public_test_method]
|
261
|
+
do_type_spec
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should accept :type(s)_and_descendents => /T1/, :methods => [m, ...]" do
|
265
|
+
@types_option = :types_and_descendents
|
266
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
267
|
+
@method_spec = [:public_test_method]
|
211
268
|
do_type_spec
|
212
269
|
end
|
213
270
|
|
214
271
|
it "should accept :type(s) => /T1/, :methods => m" do
|
215
|
-
@type_spec = /
|
216
|
-
@method_spec = :
|
272
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
273
|
+
@method_spec = :public_test_method
|
217
274
|
do_type_spec
|
218
275
|
end
|
219
276
|
|
220
277
|
it "should accept :type(s) => /T1/, :methods => /m/" do
|
221
|
-
@type_spec = /
|
222
|
-
@method_spec = /
|
278
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
279
|
+
@method_spec = /test_method/
|
223
280
|
do_type_spec
|
224
281
|
end
|
225
282
|
|
226
283
|
it "should accept :type(s) => ..., :methods => ..., :method_options => [:exclude_ancestor_methods] to exclude methods defined in ancestors" do
|
227
|
-
@type_spec = /
|
228
|
-
@method_spec = /
|
284
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
285
|
+
@method_spec = /test_method/
|
229
286
|
@method_options = [:exclude_ancestor_methods]
|
230
287
|
do_type_spec
|
231
288
|
end
|
232
289
|
|
233
290
|
it "should accept :type(s) => ..., :methods => ..., :method_options => [:instance, :public] to match only instance and public (both are the defaults) methods" do
|
234
|
-
@type_spec = /
|
235
|
-
@method_spec = /
|
291
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
292
|
+
@method_spec = /test_method/
|
236
293
|
@method_options = [:instance, :public]
|
237
294
|
do_type_spec
|
238
295
|
end
|
239
296
|
|
240
297
|
%w[public protected private].each do |protection|
|
241
298
|
it "should accept :type(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
242
|
-
@type_spec = /
|
243
|
-
@method_spec = /
|
299
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
300
|
+
@method_spec = /test_method/
|
244
301
|
@method_options = [protection.intern]
|
245
302
|
@protection = protection
|
246
303
|
do_type_spec
|
@@ -248,8 +305,8 @@ describe Aspect, "#new with a :type(s) parameter and a :method(s) parameter" do
|
|
248
305
|
end
|
249
306
|
|
250
307
|
it "should accept :type(s) => ..., :methods => ..., :method_options => [:class] to match only public (default) class methods" do
|
251
|
-
@type_spec = /
|
252
|
-
@method_spec = /
|
308
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
309
|
+
@method_spec = /test_method/
|
253
310
|
@method_options = [:class]
|
254
311
|
@are_class_methods = true
|
255
312
|
do_type_spec
|
@@ -257,8 +314,8 @@ describe Aspect, "#new with a :type(s) parameter and a :method(s) parameter" do
|
|
257
314
|
|
258
315
|
%w[public private].each do |protection|
|
259
316
|
it "should accept :type(s) => ..., :methods => ..., :method_options => [:class, :#{protection.intern}] to match only class #{protection} methods" do
|
260
|
-
@type_spec = /
|
261
|
-
@method_spec = /
|
317
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
318
|
+
@method_spec = /test_method/
|
262
319
|
@method_options = [:class, protection.intern]
|
263
320
|
@protection = protection
|
264
321
|
@are_class_methods = true
|
@@ -268,7 +325,7 @@ describe Aspect, "#new with a :type(s) parameter and a :method(s) parameter" do
|
|
268
325
|
end
|
269
326
|
|
270
327
|
|
271
|
-
describe Aspect, "
|
328
|
+
describe Aspect, ".new with a :type(s) parameter and a :attribute(s) parameter" do
|
272
329
|
before :each do
|
273
330
|
@protection = 'public'
|
274
331
|
@attribute_options = []
|
@@ -278,137 +335,137 @@ describe Aspect, "#new with a :type(s) parameter and a :attribute(s) parameter"
|
|
278
335
|
def do_type_attribute_spec
|
279
336
|
aspect = nil
|
280
337
|
advice_called = false
|
281
|
-
aspect = Aspect.new :before, :types => @type_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, *args|
|
338
|
+
aspect = Aspect.new :before, :types => @type_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, obj, *args|
|
282
339
|
advice_called = true
|
283
340
|
jp.should_not be_nil
|
284
341
|
expected_args = make_array(@expected_args)
|
285
342
|
args.should == expected_args
|
286
343
|
args.size.should == expected_args.size
|
287
344
|
end
|
288
|
-
|
345
|
+
object = Aquarium::AspectInvocationTestClass.new
|
289
346
|
@expected_args = nil
|
290
|
-
|
347
|
+
object.method("#{@protection}_test_method_args".intern).call
|
291
348
|
@expected_args = :a1
|
292
|
-
|
349
|
+
object.method("#{@protection}_test_method_args=".intern).call @expected_args
|
293
350
|
advice_called.should be_true
|
294
351
|
aspect.unadvise
|
295
352
|
end
|
296
353
|
|
297
354
|
it "should accept :type(s) => [T1, ...], :attribute(s) => [a, ...]" do
|
298
|
-
@type_spec = [
|
299
|
-
@attribute_spec = [:
|
355
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
356
|
+
@attribute_spec = [:public_test_method_args]
|
300
357
|
do_type_attribute_spec
|
301
358
|
end
|
302
359
|
|
303
360
|
it "should accept :type(s) => [T1, ...], :attribute(s) => a" do
|
304
|
-
@type_spec = [
|
305
|
-
@attribute_spec = :
|
361
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
362
|
+
@attribute_spec = :public_test_method_args
|
306
363
|
do_type_attribute_spec
|
307
364
|
end
|
308
365
|
|
309
366
|
it "should accept :type(s) => [T1, ...], :attribute(s) => /a/" do
|
310
|
-
@type_spec = [
|
311
|
-
@attribute_spec = /
|
367
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
368
|
+
@attribute_spec = /test_method_args/
|
312
369
|
do_type_attribute_spec
|
313
370
|
end
|
314
371
|
|
315
372
|
it "should accept :type(s) => T1, :attribute(s) => [a]" do
|
316
|
-
@type_spec =
|
317
|
-
@attribute_spec = [:
|
373
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
374
|
+
@attribute_spec = [:public_test_method_args]
|
318
375
|
do_type_attribute_spec
|
319
376
|
end
|
320
377
|
|
321
378
|
it "should accept :type(s) => T1, :attribute(s) => a" do
|
322
|
-
@type_spec =
|
323
|
-
@attribute_spec = :
|
379
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
380
|
+
@attribute_spec = :public_test_method_args
|
324
381
|
do_type_attribute_spec
|
325
382
|
end
|
326
383
|
|
327
384
|
it "should accept :type(s) => T1, :attribute(s) => /a/" do
|
328
|
-
@type_spec =
|
329
|
-
@attribute_spec = /
|
385
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
386
|
+
@attribute_spec = /test_method_args/
|
330
387
|
do_type_attribute_spec
|
331
388
|
end
|
332
389
|
|
333
390
|
it "should accept :type(s) => /T1/, :attribute(s) => [a, ...]" do
|
334
|
-
@type_spec = /
|
335
|
-
@attribute_spec = [:
|
391
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
392
|
+
@attribute_spec = [:public_test_method_args]
|
336
393
|
do_type_attribute_spec
|
337
394
|
end
|
338
395
|
|
339
396
|
it "should accept :type(s) => /T1/, :attribute(s) => a" do
|
340
|
-
@type_spec = /
|
341
|
-
@attribute_spec = :
|
397
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
398
|
+
@attribute_spec = :public_test_method_args
|
342
399
|
do_type_attribute_spec
|
343
400
|
end
|
344
401
|
|
345
402
|
it "should accept :type(s) => /T1/, :attribute(s) => a" do
|
346
|
-
@type_spec = /
|
347
|
-
@attribute_spec = /
|
403
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
404
|
+
@attribute_spec = /test_method_args/
|
348
405
|
do_type_attribute_spec
|
349
406
|
end
|
350
407
|
|
351
408
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:readers, :writers] to include both attribute reader and writer methods (default)" do
|
352
|
-
@type_spec = /
|
353
|
-
@attribute_spec = /
|
409
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
410
|
+
@attribute_spec = /test_method_args/
|
354
411
|
@attribute_options = [:readers, :writers]
|
355
412
|
do_type_attribute_spec
|
356
413
|
end
|
357
414
|
|
358
415
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:readers] to include only attribute reader methods" do
|
359
|
-
@type_spec = /
|
360
|
-
@attribute_spec = /
|
416
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
417
|
+
@attribute_spec = /test_method_args/
|
361
418
|
@attribute_options = [:readers]
|
362
419
|
do_type_attribute_spec
|
363
420
|
end
|
364
421
|
|
365
422
|
it "should accept attribute option :reader as a synonym for :readers" do
|
366
|
-
@type_spec = /
|
367
|
-
@attribute_spec = /
|
423
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
424
|
+
@attribute_spec = /test_method_args/
|
368
425
|
@attribute_options = [:reader]
|
369
426
|
do_type_attribute_spec
|
370
427
|
end
|
371
428
|
|
372
429
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:writers] to include only attribute writer methods" do
|
373
|
-
@type_spec = /
|
374
|
-
@attribute_spec = /
|
430
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
431
|
+
@attribute_spec = /test_method_args/
|
375
432
|
@attribute_options = [:writers]
|
376
433
|
do_type_attribute_spec
|
377
434
|
end
|
378
435
|
|
379
436
|
it "should accept attribute option :writer as a synonym for :writers" do
|
380
|
-
@type_spec = /
|
381
|
-
@attribute_spec = /
|
437
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
438
|
+
@attribute_spec = /test_method_args/
|
382
439
|
@attribute_options = [:writer]
|
383
440
|
do_type_attribute_spec
|
384
441
|
end
|
385
442
|
|
386
443
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :readers, :writers] to include both attribute reader and writer methods (default) for class methods" do
|
387
|
-
@type_spec = /
|
388
|
-
@attribute_spec = /
|
444
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
445
|
+
@attribute_spec = /test_method_args/
|
389
446
|
@attribute_options = [:class, :readers, :writers]
|
390
447
|
do_type_attribute_spec
|
391
448
|
end
|
392
449
|
|
393
450
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :readers] to include only attribute reader class methods" do
|
394
|
-
@type_spec = /
|
395
|
-
@attribute_spec = /
|
451
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
452
|
+
@attribute_spec = /test_method_args/
|
396
453
|
@attribute_options = [:class, :readers]
|
397
454
|
do_type_attribute_spec
|
398
455
|
end
|
399
456
|
|
400
457
|
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :writers] to include only attribute writer class methods" do
|
401
|
-
@type_spec = /
|
402
|
-
@attribute_spec = /
|
458
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
459
|
+
@attribute_spec = /test_method_args/
|
403
460
|
@attribute_options = [:class, :writers]
|
404
461
|
do_type_attribute_spec
|
405
462
|
end
|
406
463
|
end
|
407
464
|
|
408
|
-
describe Aspect, "
|
465
|
+
describe Aspect, ".new with a :object(s) parameter and a :method(s) parameter" do
|
409
466
|
before :each do
|
410
|
-
@
|
411
|
-
@
|
467
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
468
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
412
469
|
@protection = 'public'
|
413
470
|
@method_options = []
|
414
471
|
end
|
@@ -416,80 +473,80 @@ describe Aspect, "#new with a :object(s) parameter and a :method(s) parameter" d
|
|
416
473
|
def do_object_spec
|
417
474
|
aspect = nil
|
418
475
|
advice_called = false
|
419
|
-
aspect = Aspect.new :before, :objects => @object_spec, :methods => @method_spec, :method_options => @method_options do |jp, *args|
|
476
|
+
aspect = Aspect.new :before, :objects => @object_spec, :methods => @method_spec, :method_options => @method_options do |jp, obj, *args|
|
420
477
|
advice_called = true
|
421
478
|
jp.should_not be_nil
|
422
479
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
423
480
|
end
|
424
481
|
make_array(@object_spec).each do |object|
|
425
|
-
object.method("#{@protection}
|
482
|
+
object.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
426
483
|
end
|
427
484
|
advice_called.should be_true
|
428
485
|
aspect.unadvise
|
429
486
|
end
|
430
487
|
|
431
488
|
it "should accept :object(s) => [o1, ...], :methods => [m, ...]" do
|
432
|
-
@object_spec = [@
|
433
|
-
@method_spec = [:
|
489
|
+
@object_spec = [@object1, @object2]
|
490
|
+
@method_spec = [:public_test_method]
|
434
491
|
do_object_spec
|
435
492
|
end
|
436
493
|
|
437
494
|
it "should accept :object(s) => [o1, ...], :methods => m" do
|
438
|
-
@object_spec = [@
|
439
|
-
@method_spec = :
|
495
|
+
@object_spec = [@object1, @object2]
|
496
|
+
@method_spec = :public_test_method
|
440
497
|
do_object_spec
|
441
498
|
end
|
442
499
|
|
443
500
|
it "should accept :object(s) => [o1, ...], :methods => /m/" do
|
444
|
-
@object_spec = [@
|
445
|
-
@method_spec = /
|
501
|
+
@object_spec = [@object1, @object2]
|
502
|
+
@method_spec = /test_method/
|
446
503
|
do_object_spec
|
447
504
|
end
|
448
505
|
|
449
506
|
it "should accept :object(s) => o1, :methods => [m, ...]" do
|
450
|
-
@object_spec = @
|
451
|
-
@method_spec = [:
|
507
|
+
@object_spec = @object1
|
508
|
+
@method_spec = [:public_test_method]
|
452
509
|
do_object_spec
|
453
510
|
end
|
454
511
|
|
455
512
|
it "should accept :object(s) => o1, :methods => m" do
|
456
|
-
@object_spec = @
|
457
|
-
@method_spec = :
|
513
|
+
@object_spec = @object1
|
514
|
+
@method_spec = :public_test_method
|
458
515
|
do_object_spec
|
459
516
|
end
|
460
517
|
|
461
518
|
it "should accept :object(s) => o1, :methods => /m/" do
|
462
|
-
@object_spec = @
|
463
|
-
@method_spec = /
|
519
|
+
@object_spec = @object1
|
520
|
+
@method_spec = /test_method/
|
464
521
|
do_object_spec
|
465
522
|
end
|
466
523
|
|
467
524
|
it "should accept :object(s) => ..., :methods => ..., :method_options => [:exclude_ancestor_methods] to exclude methods defined in ancestors" do
|
468
|
-
@object_spec = @
|
469
|
-
@method_spec = /
|
525
|
+
@object_spec = @object1
|
526
|
+
@method_spec = /test_method/
|
470
527
|
@method_options = [:exclude_ancestor_methods]
|
471
528
|
do_object_spec
|
472
529
|
end
|
473
530
|
|
474
531
|
it "should accept :object(s) => ..., :methods => ..., :method_options => [:instance, :public] to match only instance and public (both are the defaults) methods" do
|
475
|
-
@object_spec = @
|
476
|
-
@method_spec = /
|
532
|
+
@object_spec = @object1
|
533
|
+
@method_spec = /test_method/
|
477
534
|
@method_options = [:instance, :public]
|
478
535
|
do_object_spec
|
479
536
|
end
|
480
537
|
|
481
538
|
%w[public protected private].each do |protection|
|
482
539
|
it "should accept :object(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
483
|
-
@object_spec = @
|
484
|
-
@method_spec = /
|
540
|
+
@object_spec = @object1
|
541
|
+
@method_spec = /test_method/
|
485
542
|
@method_options = [protection.intern]
|
486
543
|
@protection = protection
|
487
544
|
do_object_spec
|
488
545
|
end
|
489
546
|
|
490
547
|
it "should accept :object(s) => ..., :methods => ..., :method_options => [:instance, #{protection.intern}] to match only instance #{protection} methods" do
|
491
|
-
@object_spec = @
|
492
|
-
@method_spec = /
|
548
|
+
@object_spec = @object1
|
549
|
+
@method_spec = /test_method/
|
493
550
|
@method_options = [:instance, protection.intern]
|
494
551
|
@protection = protection
|
495
552
|
do_object_spec
|
@@ -497,10 +554,10 @@ describe Aspect, "#new with a :object(s) parameter and a :method(s) parameter" d
|
|
497
554
|
end
|
498
555
|
end
|
499
556
|
|
500
|
-
describe Aspect, "
|
557
|
+
describe Aspect, ".new with a :object(s) parameter and a :attribute(s) parameter" do
|
501
558
|
before :each do
|
502
|
-
@
|
503
|
-
@
|
559
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
560
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
504
561
|
@protection = 'public'
|
505
562
|
@attribute_options = []
|
506
563
|
end
|
@@ -508,7 +565,7 @@ describe Aspect, "#new with a :object(s) parameter and a :attribute(s) parameter
|
|
508
565
|
def do_object_attribute_spec
|
509
566
|
aspect = nil
|
510
567
|
advice_called = false
|
511
|
-
aspect = Aspect.new :before, :objects => @object_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, *args|
|
568
|
+
aspect = Aspect.new :before, :objects => @object_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, obj, *args|
|
512
569
|
advice_called = true
|
513
570
|
jp.should_not be_nil
|
514
571
|
expected_args = make_array(@expected_args)
|
@@ -517,87 +574,87 @@ describe Aspect, "#new with a :object(s) parameter and a :attribute(s) parameter
|
|
517
574
|
end
|
518
575
|
make_array(@object_spec).each do |object|
|
519
576
|
@expected_args = nil
|
520
|
-
object.method("#{@protection}
|
577
|
+
object.method("#{@protection}_test_method_args".intern).call
|
521
578
|
@expected_args = :a1
|
522
|
-
object.method("#{@protection}
|
579
|
+
object.method("#{@protection}_test_method_args=".intern).call @expected_args
|
523
580
|
advice_called.should be_true
|
524
581
|
end
|
525
582
|
aspect.unadvise
|
526
583
|
end
|
527
584
|
|
528
585
|
it "should accept :object(s) => [T1, ...], :attribute(s) => [a, ...]" do
|
529
|
-
@object_spec = [@
|
530
|
-
@attribute_spec = [:
|
586
|
+
@object_spec = [@object1, @object2]
|
587
|
+
@attribute_spec = [:public_test_method_args]
|
531
588
|
do_object_attribute_spec
|
532
589
|
end
|
533
590
|
|
534
591
|
it "should accept :object(s) => [T1, ...], :attribute(s) => a" do
|
535
|
-
@object_spec = [@
|
536
|
-
@attribute_spec = :
|
592
|
+
@object_spec = [@object1, @object2]
|
593
|
+
@attribute_spec = :public_test_method_args
|
537
594
|
do_object_attribute_spec
|
538
595
|
end
|
539
596
|
|
540
597
|
it "should accept :object(s) => [T1, ...], :attribute(s) => /a/" do
|
541
|
-
@object_spec = [@
|
542
|
-
@attribute_spec = /
|
598
|
+
@object_spec = [@object1, @object2]
|
599
|
+
@attribute_spec = /test_method_args/
|
543
600
|
do_object_attribute_spec
|
544
601
|
end
|
545
602
|
|
546
603
|
it "should accept :object(s) => T1, :attribute(s) => [a]" do
|
547
|
-
@object_spec = @
|
548
|
-
@attribute_spec = [:
|
604
|
+
@object_spec = @object1
|
605
|
+
@attribute_spec = [:public_test_method_args]
|
549
606
|
do_object_attribute_spec
|
550
607
|
end
|
551
608
|
|
552
609
|
it "should accept :object(s) => T1, :attribute(s) => a" do
|
553
|
-
@object_spec = @
|
554
|
-
@attribute_spec = :
|
610
|
+
@object_spec = @object1
|
611
|
+
@attribute_spec = :public_test_method_args
|
555
612
|
do_object_attribute_spec
|
556
613
|
end
|
557
614
|
|
558
615
|
it "should accept :object(s) => T1, :attribute(s) => /a/" do
|
559
|
-
@object_spec = @
|
560
|
-
@attribute_spec = /
|
616
|
+
@object_spec = @object1
|
617
|
+
@attribute_spec = /test_method_args/
|
561
618
|
do_object_attribute_spec
|
562
619
|
end
|
563
620
|
|
564
621
|
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:readers, :writers] to include both attribute reader and writer methods (default)" do
|
565
|
-
@object_spec = @
|
566
|
-
@attribute_spec = /
|
622
|
+
@object_spec = @object1
|
623
|
+
@attribute_spec = /test_method_args/
|
567
624
|
@attribute_options = [:readers, :writers]
|
568
625
|
do_object_attribute_spec
|
569
626
|
end
|
570
627
|
|
571
628
|
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:readers] to include only attribute reader methods" do
|
572
|
-
@object_spec = @
|
573
|
-
@attribute_spec = /
|
629
|
+
@object_spec = @object1
|
630
|
+
@attribute_spec = /test_method_args/
|
574
631
|
@attribute_options = [:readers]
|
575
632
|
do_object_attribute_spec
|
576
633
|
end
|
577
634
|
|
578
635
|
it "should accept attribute option :reader as a synonym for :readers" do
|
579
|
-
@object_spec = @
|
580
|
-
@attribute_spec = /
|
636
|
+
@object_spec = @object1
|
637
|
+
@attribute_spec = /test_method_args/
|
581
638
|
@attribute_options = [:reader]
|
582
639
|
do_object_attribute_spec
|
583
640
|
end
|
584
641
|
|
585
642
|
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:writers] to include only attribute writer methods" do
|
586
|
-
@object_spec = @
|
587
|
-
@attribute_spec = /
|
643
|
+
@object_spec = @object1
|
644
|
+
@attribute_spec = /test_method_args/
|
588
645
|
@attribute_options = [:writers]
|
589
646
|
do_object_attribute_spec
|
590
647
|
end
|
591
648
|
|
592
649
|
it "should accept attribute option :writer as a synonym for :writers" do
|
593
|
-
@object_spec = @
|
594
|
-
@attribute_spec = /
|
650
|
+
@object_spec = @object1
|
651
|
+
@attribute_spec = /test_method_args/
|
595
652
|
@attribute_options = [:writer]
|
596
653
|
do_object_attribute_spec
|
597
654
|
end
|
598
655
|
end
|
599
656
|
|
600
|
-
describe Aspect, "
|
657
|
+
describe Aspect, ".new with a :pointcut parameter taking a hash with type specifications" do
|
601
658
|
before :each do
|
602
659
|
@protection = 'public'
|
603
660
|
@are_class_methods = false
|
@@ -606,77 +663,107 @@ describe Aspect, "#new with a :pointcut parameter taking a hash with type specif
|
|
606
663
|
def do_type_pointcut_spec
|
607
664
|
aspect = nil
|
608
665
|
advice_called = false
|
609
|
-
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, *args|
|
666
|
+
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, obj, *args|
|
610
667
|
advice_called = true
|
611
668
|
jp.should_not be_nil
|
612
669
|
args.size.should == 4
|
613
670
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
614
671
|
end
|
615
672
|
if @are_class_methods
|
616
|
-
|
673
|
+
Aquarium::AspectInvocationTestClass.method("#{@protection}_class_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
617
674
|
else
|
618
|
-
|
675
|
+
Aquarium::AspectInvocationTestClass.new.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
619
676
|
end
|
620
677
|
advice_called.should be_true
|
621
678
|
aspect.unadvise
|
622
679
|
end
|
623
680
|
|
624
681
|
it "should accept {:type(s) => [T1, ...], :methods => [m, ...]} " do
|
625
|
-
@pointcut_hash = {:type => [
|
682
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => [:public_test_method]}
|
626
683
|
do_type_pointcut_spec
|
627
684
|
end
|
628
685
|
|
629
686
|
it "should accept {:type(s) => [T1, ...], :methods => m} " do
|
630
|
-
@pointcut_hash = {:type => [
|
687
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method}
|
631
688
|
do_type_pointcut_spec
|
632
689
|
end
|
633
690
|
|
634
691
|
it "should accept {:type(s) => [T1, ...], :methods => /m/} " do
|
635
|
-
@pointcut_hash = {:type => [
|
692
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
693
|
+
do_type_pointcut_spec
|
694
|
+
end
|
695
|
+
|
696
|
+
it "should accept {:type(s)_and_ancestors => [T1, ...], :methods => /m/} " do
|
697
|
+
@pointcut_hash = {:type_and_ancestors => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
698
|
+
do_type_pointcut_spec
|
699
|
+
end
|
700
|
+
|
701
|
+
it "should accept {:type(s)_and_descendents => [T1, ...], :methods => /m/} " do
|
702
|
+
@pointcut_hash = {:type_and_descendents => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
636
703
|
do_type_pointcut_spec
|
637
704
|
end
|
638
705
|
|
639
706
|
it "should accept {:type(s) => T1, :methods => [m, ...]} " do
|
640
|
-
@pointcut_hash = {:type =>
|
707
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => [:public_test_method]}
|
641
708
|
do_type_pointcut_spec
|
642
709
|
end
|
643
710
|
|
644
711
|
it "should accept {:type(s) => T1, :methods => m} " do
|
645
|
-
@pointcut_hash = {:type =>
|
712
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method}
|
646
713
|
do_type_pointcut_spec
|
647
714
|
end
|
648
715
|
|
649
716
|
it "should accept {:type(s) => T1, :methods => /m/} " do
|
650
|
-
@pointcut_hash = {:type =>
|
717
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
718
|
+
do_type_pointcut_spec
|
719
|
+
end
|
720
|
+
|
721
|
+
it "should accept {:type(s)_and_ancestors => T1, :methods => /m/} " do
|
722
|
+
@pointcut_hash = {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
723
|
+
do_type_pointcut_spec
|
724
|
+
end
|
725
|
+
|
726
|
+
it "should accept {:type(s)_and_descendents => T1, :methods => /m/} " do
|
727
|
+
@pointcut_hash = {:type_and_descendents => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
651
728
|
do_type_pointcut_spec
|
652
729
|
end
|
653
730
|
|
654
731
|
it "should accept {:type(s) => /T1/, :methods => [m, ...]} " do
|
655
|
-
@pointcut_hash = {:type => /
|
732
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => [:public_test_method]}
|
656
733
|
do_type_pointcut_spec
|
657
734
|
end
|
658
735
|
|
659
736
|
it "should accept {:type(s) => /T1/, :methods => m} " do
|
660
|
-
@pointcut_hash = {:type => /
|
737
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => :public_test_method}
|
661
738
|
do_type_pointcut_spec
|
662
739
|
end
|
663
740
|
|
664
741
|
it "should accept {:type(s) => /T1/, :methods => /m/} " do
|
665
|
-
@pointcut_hash = {:type => /
|
742
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
743
|
+
do_type_pointcut_spec
|
744
|
+
end
|
745
|
+
|
746
|
+
it "should accept {:type(s)_and_ancestors => /T1/, :methods => /m/} " do
|
747
|
+
@pointcut_hash = {:type_and_ancestors => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
748
|
+
do_type_pointcut_spec
|
749
|
+
end
|
750
|
+
|
751
|
+
it "should accept {:type(s)_and_descendents => /T1/, :methods => /m/} " do
|
752
|
+
@pointcut_hash = {:type_and_descendents => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
666
753
|
do_type_pointcut_spec
|
667
754
|
end
|
668
755
|
|
669
756
|
%w[public protected private].each do |protection|
|
670
757
|
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:instance, #{protection}]} " do
|
671
758
|
@protection = protection
|
672
|
-
@pointcut_hash = {:type =>
|
759
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:instance, protection.intern]}
|
673
760
|
do_type_pointcut_spec
|
674
761
|
end
|
675
762
|
end
|
676
763
|
|
677
764
|
%w[public private].each do |protection|
|
678
765
|
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:class, #{protection}]} " do
|
679
|
-
@pointcut_hash = {:type =>
|
766
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /class_test_method/, :method_options =>[:class, protection.intern]}
|
680
767
|
@protection = protection
|
681
768
|
@are_class_methods = true
|
682
769
|
do_type_pointcut_spec
|
@@ -684,133 +771,133 @@ describe Aspect, "#new with a :pointcut parameter taking a hash with type specif
|
|
684
771
|
end
|
685
772
|
|
686
773
|
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:instance]} defaults to public methods" do
|
687
|
-
@pointcut_hash = {:type =>
|
774
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:instance]}
|
688
775
|
do_type_pointcut_spec
|
689
776
|
end
|
690
777
|
|
691
778
|
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:class]} defaults to public class methods" do
|
692
|
-
@pointcut_hash = {:type =>
|
779
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:class]}
|
693
780
|
@are_class_methods = true
|
694
781
|
do_type_pointcut_spec
|
695
782
|
end
|
696
783
|
end
|
697
784
|
|
698
|
-
describe Aspect, "
|
785
|
+
describe Aspect, ".new with a :pointcut parameter taking a hash with object specifications" do
|
699
786
|
before :each do
|
700
787
|
@protection = 'public'
|
701
788
|
@expected_advice_count = 2
|
702
|
-
@
|
703
|
-
@
|
789
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
790
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
704
791
|
end
|
705
792
|
|
706
793
|
def do_object_pointcut_spec
|
707
794
|
aspect = nil
|
708
795
|
advice_count = 0
|
709
|
-
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, *args|
|
796
|
+
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, obj, *args|
|
710
797
|
advice_count += 1
|
711
798
|
jp.should_not be_nil
|
712
799
|
args.size.should == 4
|
713
800
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
714
801
|
end
|
715
|
-
@
|
716
|
-
@
|
802
|
+
@object1.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
803
|
+
@object2.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
717
804
|
advice_count.should == @expected_advice_count
|
718
805
|
aspect.unadvise
|
719
806
|
end
|
720
807
|
|
721
808
|
it "should accept {:objects => [o1, ...], :methods => [m, ...]} " do
|
722
|
-
@pointcut_hash = {:objects => [@
|
809
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => [:public_test_method]}
|
723
810
|
do_object_pointcut_spec
|
724
811
|
end
|
725
812
|
|
726
813
|
it "should accept {:objects => [o1, ...], :methods => m} " do
|
727
|
-
@pointcut_hash = {:objects => [@
|
814
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => :public_test_method}
|
728
815
|
do_object_pointcut_spec
|
729
816
|
end
|
730
817
|
|
731
818
|
it "should accept {:objects => [o1, ...], :methods => /m/} " do
|
732
|
-
@pointcut_hash = {:objects => [@
|
819
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => /test_method/}
|
733
820
|
do_object_pointcut_spec
|
734
821
|
end
|
735
822
|
|
736
823
|
it "should accept {:object => o1, :methods => [m, ...]} " do
|
737
824
|
@expected_advice_count = 1
|
738
|
-
@pointcut_hash = {:object => @
|
825
|
+
@pointcut_hash = {:object => @object1, :methods => [:public_test_method]}
|
739
826
|
do_object_pointcut_spec
|
740
827
|
end
|
741
828
|
|
742
829
|
it "should accept {:objects => o1, :methods => m} " do
|
743
830
|
@expected_advice_count = 1
|
744
|
-
@pointcut_hash = {:objects => @
|
831
|
+
@pointcut_hash = {:objects => @object1, :methods => :public_test_method}
|
745
832
|
do_object_pointcut_spec
|
746
833
|
end
|
747
834
|
|
748
835
|
it "should accept {:objects => o1, :methods => /m/} " do
|
749
836
|
@expected_advice_count = 1
|
750
|
-
@pointcut_hash = {:objects => @
|
837
|
+
@pointcut_hash = {:objects => @object1, :methods => /test_method/}
|
751
838
|
do_object_pointcut_spec
|
752
839
|
end
|
753
840
|
end
|
754
841
|
|
755
|
-
describe Aspect, "
|
842
|
+
describe Aspect, ".new with a :pointcut parameter and a Pointcut object or an array of Pointcuts" do
|
756
843
|
def do_pointcut_pointcut_spec
|
757
844
|
aspect = nil
|
758
845
|
advice_called = false
|
759
|
-
aspect = Aspect.new :before, :pointcut => @pointcuts do |jp, *args|
|
846
|
+
aspect = Aspect.new :before, :pointcut => @pointcuts do |jp, obj, *args|
|
760
847
|
advice_called = true
|
761
848
|
jp.should_not be_nil
|
762
849
|
args.size.should == 4
|
763
850
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
764
851
|
end
|
765
|
-
|
852
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
766
853
|
advice_called.should be_true
|
767
854
|
aspect.unadvise
|
768
855
|
end
|
769
856
|
|
770
857
|
it "should accept a single Pointcut object." do
|
771
|
-
@pointcuts = Pointcut.new :type => [
|
858
|
+
@pointcuts = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
772
859
|
do_pointcut_pointcut_spec
|
773
860
|
end
|
774
861
|
|
775
862
|
it "should accept an array of Pointcut objects." do
|
776
|
-
pointcut1 = Pointcut.new :type => [
|
777
|
-
pointcut2 = Pointcut.new :type => [
|
863
|
+
pointcut1 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
864
|
+
pointcut2 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_class_test_method, :method_options => [:class]
|
778
865
|
@pointcuts = [pointcut1, pointcut2]
|
779
866
|
do_pointcut_pointcut_spec
|
780
867
|
end
|
781
868
|
end
|
782
869
|
|
783
|
-
describe Aspect, "
|
870
|
+
describe Aspect, ".new with a :pointcut parameter and an array of Pointcuts" do
|
784
871
|
it "should treat the array as if it is one Pointcut \"or'ed\" together." do
|
785
872
|
advice_called = 0
|
786
|
-
advice = Proc.new {|jp, *args|
|
873
|
+
advice = Proc.new {|jp, obj, *args|
|
787
874
|
advice_called += 1
|
788
875
|
jp.should_not be_nil
|
789
876
|
args.size.should == 4
|
790
877
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
791
878
|
}
|
792
|
-
pointcut1 = Pointcut.new :type => [
|
793
|
-
pointcut2 = Pointcut.new :type => [
|
879
|
+
pointcut1 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
880
|
+
pointcut2 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_class_test_method, :method_options => [:class]
|
794
881
|
pointcut12 = pointcut1.or pointcut2
|
795
882
|
aspect1 = Aspect.new :before, :pointcut => [pointcut1, pointcut2], :advice => advice
|
796
|
-
|
797
|
-
|
883
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
884
|
+
Aquarium::AspectInvocationTestClass.public_class_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
798
885
|
advice_called.should == 2
|
799
886
|
aspect1.unadvise
|
800
887
|
advice_called = 0
|
801
888
|
aspect2 = Aspect.new :before, :pointcut => pointcut12, :advice => advice
|
802
|
-
|
803
|
-
|
889
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
890
|
+
Aquarium::AspectInvocationTestClass.public_class_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
804
891
|
advice_called.should == 2
|
805
892
|
aspect2.unadvise
|
806
893
|
aspect1.join_points_matched.should eql(aspect2.join_points_matched)
|
807
894
|
end
|
808
895
|
end
|
809
896
|
|
810
|
-
describe Aspect, "
|
897
|
+
describe Aspect, ".new with a :type(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters" do
|
811
898
|
before :each do
|
812
|
-
@advice = proc {|jp
|
813
|
-
@expected_methods = [:
|
899
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
900
|
+
@expected_methods = [:public_test_method]
|
814
901
|
end
|
815
902
|
after :each do
|
816
903
|
@aspect1.unadvise
|
@@ -818,41 +905,82 @@ describe Aspect, "#new with a :type(s) parameter and a :method(s) parameter or o
|
|
818
905
|
end
|
819
906
|
|
820
907
|
it "should advise equivalent join points when :type => T and :method => m is used or :pointcut =>{:type => T, :method => m} is used." do
|
821
|
-
@aspect1 = Aspect.new :after, :type =>
|
822
|
-
@aspect2 = Aspect.new :after, :pointcut => {:type =>
|
908
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
909
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
823
910
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
824
911
|
end
|
825
912
|
|
826
913
|
it "should advise equivalent join points when :type => T and :method => m is used or :pointcut => pointcut is used, where pointcut matches :type => T and :method => m." do
|
827
|
-
@aspect1 = Aspect.new :after, :type =>
|
828
|
-
pointcut = Aquarium::Aspects::Pointcut.new :type =>
|
914
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
915
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
829
916
|
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
830
917
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
831
918
|
end
|
832
919
|
|
833
920
|
it "should advise equivalent join points when :pointcut =>{:type => T, :method => m} is used or :pointcut => pointcut is used, where pointcut matches :type => T and :method => m." do
|
834
|
-
@aspect1 = Aspect.new :after, :pointcut => {:type =>
|
835
|
-
pointcut = Aquarium::Aspects::Pointcut.new :type =>
|
921
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
922
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
836
923
|
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
837
924
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
838
925
|
end
|
839
926
|
|
840
927
|
it "should advise an equivalent join point when :type => T and :method => m is used or :pointcut => join_point is used, where join_point matches :type => T and :method => m." do
|
841
|
-
@aspect1 = Aspect.new :after, :type =>
|
842
|
-
join_point = Aquarium::Aspects::JoinPoint.new :type =>
|
928
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
929
|
+
join_point = Aquarium::Aspects::JoinPoint.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
843
930
|
@aspect2 = Aspect.new :after, :pointcut => join_point, &@advice
|
844
931
|
join_points_should_be_equal 1, @aspect1, @aspect2
|
845
932
|
end
|
933
|
+
|
934
|
+
it "should advise equivalent join points when :type_and_ancestors => T and :method => m is used or :pointcut =>{:type_and_ancestors => T, :method => m} is used." do
|
935
|
+
@aspect1 = Aspect.new :after, :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
936
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
937
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
938
|
+
end
|
939
|
+
|
940
|
+
it "should advise equivalent join points when :type_and_ancestors => T and :method => m is used or :pointcut => pointcut is used, where pointcut matches :type_and_ancestors => T and :method => m." do
|
941
|
+
@aspect1 = Aspect.new :after, :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
942
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
943
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
944
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
945
|
+
end
|
946
|
+
|
947
|
+
it "should advise equivalent join points when :pointcut =>{:type_and_ancestors => T, :method => m} is used or :pointcut => pointcut is used, where pointcut matches :type_and_ancestors => T and :method => m." do
|
948
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
949
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
950
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
951
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
952
|
+
end
|
953
|
+
|
954
|
+
it "should advise equivalent join points when :type_and_descendents => T and :method => m is used or :pointcut =>{:type_and_descendents => T, :method => m} is used." do
|
955
|
+
@aspect1 = Aspect.new :after, :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
956
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
957
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
958
|
+
end
|
959
|
+
|
960
|
+
it "should advise equivalent join points when :type_and_descendents => T and :method => m is used or :pointcut => pointcut is used, where pointcut matches :type_and_descendents => T and :method => m." do
|
961
|
+
@aspect1 = Aspect.new :after, :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
962
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
963
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
964
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
965
|
+
end
|
966
|
+
|
967
|
+
it "should advise equivalent join points when :pointcut =>{:type_and_descendents => T, :method => m} is used or :pointcut => pointcut is used, where pointcut matches :type_and_descendents => T and :method => m." do
|
968
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
969
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
970
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
971
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
972
|
+
end
|
973
|
+
|
846
974
|
end
|
847
975
|
|
848
|
-
describe Aspect, "
|
976
|
+
describe Aspect, ".new with a :type(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters" do
|
849
977
|
class ClassWithAttrib1
|
850
978
|
def dummy; end
|
851
979
|
attr_accessor :state
|
852
980
|
end
|
853
981
|
|
854
982
|
before :each do
|
855
|
-
@advice = proc {|jp
|
983
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
856
984
|
@expected_methods = [:state, :state=]
|
857
985
|
end
|
858
986
|
after :each do
|
@@ -902,10 +1030,10 @@ describe Aspect, "#new with a :type(s) parameter and an :attributes(s) parameter
|
|
902
1030
|
end
|
903
1031
|
end
|
904
1032
|
|
905
|
-
describe Aspect, "
|
1033
|
+
describe Aspect, ".new with a :object(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters" do
|
906
1034
|
before :each do
|
907
|
-
@advice = proc {|jp
|
908
|
-
@expected_methods = [:
|
1035
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
1036
|
+
@expected_methods = [:public_test_method]
|
909
1037
|
end
|
910
1038
|
after :each do
|
911
1039
|
@aspect1.unadvise
|
@@ -913,30 +1041,30 @@ describe Aspect, "#new with a :object(s) parameter and a :method(s) parameter or
|
|
913
1041
|
end
|
914
1042
|
|
915
1043
|
it "should advise equivalent join points when :object => o and :method => m is used or :pointcut =>{:object => o, :method => m} is used." do
|
916
|
-
|
917
|
-
@aspect1 = Aspect.new :after, :object =>
|
918
|
-
@aspect2 = Aspect.new :after, :pointcut => {:object =>
|
1044
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1045
|
+
@aspect1 = Aspect.new :after, :object => object, :method => :public_test_method, &@advice
|
1046
|
+
@aspect2 = Aspect.new :after, :pointcut => {:object => object, :method => :public_test_method}, &@advice
|
919
1047
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
920
1048
|
end
|
921
1049
|
|
922
1050
|
it "should advise equivalent join points when :object => o and :method => m is used or :pointcut => pointcut is used, where pointcut matches :object => o and :method => m." do
|
923
|
-
|
924
|
-
@aspect1 = Aspect.new :after, :object =>
|
925
|
-
pointcut = Aquarium::Aspects::Pointcut.new :object =>
|
1051
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1052
|
+
@aspect1 = Aspect.new :after, :object => object, :method => :public_test_method, &@advice
|
1053
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => object, :method => :public_test_method
|
926
1054
|
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
927
1055
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
928
1056
|
end
|
929
1057
|
|
930
1058
|
it "should advise equivalent join points when :pointcut =>{:object => o, :method => m} is used or :pointcut => pointcut is used, where pointcut matches :object => o and :method => m." do
|
931
|
-
|
932
|
-
@aspect1 = Aspect.new :after, :pointcut => {:object =>
|
933
|
-
pointcut = Aquarium::Aspects::Pointcut.new :object =>
|
1059
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1060
|
+
@aspect1 = Aspect.new :after, :pointcut => {:object => object, :method => :public_test_method}, &@advice
|
1061
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => object, :method => :public_test_method
|
934
1062
|
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
935
1063
|
aspects_should_be_equal 1, @aspect1, @aspect2
|
936
1064
|
end
|
937
1065
|
end
|
938
1066
|
|
939
|
-
describe Aspect, "
|
1067
|
+
describe Aspect, ".new with a :object(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters" do
|
940
1068
|
class ClassWithAttrib2
|
941
1069
|
def initialize *args
|
942
1070
|
@state = args
|
@@ -946,7 +1074,7 @@ describe Aspect, "#new with a :object(s) parameter and an :attributes(s) paramet
|
|
946
1074
|
end
|
947
1075
|
|
948
1076
|
before :each do
|
949
|
-
@advice = proc {|jp
|
1077
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
950
1078
|
@object = ClassWithAttrib2.new
|
951
1079
|
@expected_methods = [:state, :state=]
|
952
1080
|
end
|
@@ -997,111 +1125,137 @@ describe Aspect, "#new with a :object(s) parameter and an :attributes(s) paramet
|
|
997
1125
|
end
|
998
1126
|
end
|
999
1127
|
|
1000
|
-
describe Aspect, "
|
1128
|
+
describe Aspect, ".new block for advice" do
|
1001
1129
|
it "should accept a block as the advice to use." do
|
1002
|
-
|
1130
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1003
1131
|
advice_called = false
|
1004
|
-
aspect = Aspect.new :before, :object =>
|
1132
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method do |jp, obj, *args|
|
1005
1133
|
advice_called = true
|
1006
1134
|
jp.should_not be_nil
|
1007
1135
|
args.size.should == 4
|
1008
1136
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1009
1137
|
end
|
1010
|
-
|
1138
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1011
1139
|
advice_called.should be_true
|
1012
1140
|
aspect.unadvise
|
1013
1141
|
end
|
1014
1142
|
|
1015
1143
|
it "should accept an :advice => Proc parameter indicating the advice to use." do
|
1016
|
-
|
1144
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1017
1145
|
advice_called = false
|
1018
|
-
advice = Proc.new {|jp, *args|
|
1146
|
+
advice = Proc.new {|jp, obj, *args|
|
1019
1147
|
advice_called = true
|
1020
1148
|
jp.should_not be_nil
|
1021
1149
|
args.size.should == 4
|
1022
1150
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1023
1151
|
}
|
1024
|
-
aspect = Aspect.new :before, :object =>
|
1025
|
-
|
1152
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice
|
1153
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1026
1154
|
advice_called.should be_true
|
1027
1155
|
aspect.unadvise
|
1028
1156
|
end
|
1029
1157
|
|
1030
1158
|
it "should accept a :call => Proc parameter as a synonym for :advice." do
|
1031
|
-
|
1159
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1032
1160
|
advice_called = false
|
1033
|
-
advice = Proc.new {|jp, *args|
|
1161
|
+
advice = Proc.new {|jp, obj, *args|
|
1034
1162
|
advice_called = true
|
1035
1163
|
jp.should_not be_nil
|
1036
1164
|
args.size.should == 4
|
1037
1165
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1038
1166
|
}
|
1039
|
-
aspect = Aspect.new :before, :object =>
|
1040
|
-
|
1167
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :call => advice
|
1168
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1041
1169
|
advice_called.should be_true
|
1042
1170
|
aspect.unadvise
|
1043
1171
|
end
|
1044
1172
|
|
1045
1173
|
it "should accept a :invoke => Proc parameter as a synonym for :advice." do
|
1046
|
-
|
1174
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1047
1175
|
advice_called = false
|
1048
|
-
advice = Proc.new {|jp, *args|
|
1176
|
+
advice = Proc.new {|jp, obj, *args|
|
1049
1177
|
advice_called = true
|
1050
1178
|
jp.should_not be_nil
|
1051
1179
|
args.size.should == 4
|
1052
1180
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1053
1181
|
}
|
1054
|
-
aspect = Aspect.new :before, :object =>
|
1055
|
-
|
1182
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :invoke => advice
|
1183
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1056
1184
|
advice_called.should be_true
|
1057
1185
|
aspect.unadvise
|
1058
1186
|
end
|
1059
1187
|
|
1060
1188
|
it "should accept a :advise_with => Proc parameter as a synonym for :advice." do
|
1061
|
-
|
1189
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1062
1190
|
advice_called = false
|
1063
|
-
advice = Proc.new {|jp, *args|
|
1191
|
+
advice = Proc.new {|jp, obj, *args|
|
1064
1192
|
advice_called = true
|
1065
1193
|
jp.should_not be_nil
|
1066
1194
|
args.size.should == 4
|
1067
1195
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1068
1196
|
}
|
1069
|
-
aspect = Aspect.new :before, :object =>
|
1070
|
-
|
1197
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advise_with => advice
|
1198
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1071
1199
|
advice_called.should be_true
|
1072
1200
|
aspect.unadvise
|
1073
1201
|
end
|
1074
1202
|
|
1075
1203
|
it "should ignore all other advice parameters if a block is given." do
|
1076
|
-
|
1204
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1077
1205
|
advice_called = false
|
1078
|
-
advice1 = Proc.new {|jp, *args| fail "advice1"}
|
1079
|
-
advice2 = Proc.new {|jp, *args| fail "advice2"}
|
1080
|
-
aspect = Aspect.new :before, :object =>
|
1206
|
+
advice1 = Proc.new {|jp, obj, *args| fail "advice1"}
|
1207
|
+
advice2 = Proc.new {|jp, obj, *args| fail "advice2"}
|
1208
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice1, :invoke => advice2 do |jp, obj, *args|
|
1081
1209
|
advice_called = true
|
1082
1210
|
end
|
1083
|
-
|
1211
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1084
1212
|
advice_called.should be_true
|
1085
1213
|
aspect.unadvise
|
1086
1214
|
end
|
1087
1215
|
|
1088
1216
|
it "should ignore all but the last advice parameter, using any synonym, if there is no advice block." do
|
1089
|
-
|
1217
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1090
1218
|
advice_called = false
|
1091
|
-
advice1 = Proc.new {|jp, *args|
|
1219
|
+
advice1 = Proc.new {|jp, obj, *args|
|
1092
1220
|
advice_called = true
|
1093
1221
|
jp.should_not be_nil
|
1094
1222
|
args.size.should == 4
|
1095
1223
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1096
1224
|
}
|
1097
|
-
advice2 = Proc.new {|jp, *args| raise "should not be called"}
|
1098
|
-
aspect = Aspect.new :before, :object =>
|
1099
|
-
|
1225
|
+
advice2 = Proc.new {|jp, obj, *args| raise "should not be called"}
|
1226
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice2, :advice => advice1
|
1227
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1100
1228
|
advice_called.should be_true
|
1101
1229
|
aspect.unadvise
|
1102
1230
|
end
|
1103
1231
|
end
|
1104
1232
|
|
1233
|
+
describe Aspect, ".new advice block or proc parameter list" do
|
1234
|
+
it "should raise if obsolete |jp, *args| list is used." do
|
1235
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method do |jp, *args|; end }.should raise_error(Aquarium::Utils::InvalidOptions)
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
it "should accept an argument list matching |jp, object, *args|." do
|
1239
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp, object, *args|; end }.should_not raise_error(Exception)
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it "should accept an argument list matching |jp, object|." do
|
1243
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp, object|; end }.should_not raise_error(Exception)
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
it "should accept an argument list matching |jp|." do
|
1247
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp|; end }.should_not raise_error(Exception)
|
1248
|
+
end
|
1249
|
+
|
1250
|
+
it "should accept an argument list matching ||." do
|
1251
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do ||; end }.should_not raise_error(Exception)
|
1252
|
+
end
|
1253
|
+
|
1254
|
+
it "should accept no argument list." do
|
1255
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do; end }.should_not raise_error(Exception)
|
1256
|
+
end
|
1257
|
+
end
|
1258
|
+
|
1105
1259
|
|
1106
1260
|
class ExcludeBase
|
1107
1261
|
def doit; end
|
@@ -1128,13 +1282,13 @@ class Exclude1c < Exclude1
|
|
1128
1282
|
def doit3; end
|
1129
1283
|
end
|
1130
1284
|
|
1131
|
-
describe Aspect, "
|
1285
|
+
describe Aspect, ".new with a :type(s) parameter and an :exclude_type(s), and :exclude_type(s)_and_ancestors, or an :exclude_type(s)_and_descendents parameter" do
|
1132
1286
|
def do_exclude_types exclude_type_sym
|
1133
1287
|
included_types = [DontExclude1, DontExclude2]
|
1134
1288
|
excluded_types = [Exclude1, Exclude2]
|
1135
1289
|
aspect = nil
|
1136
1290
|
advice_called = false
|
1137
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), exclude_type_sym => excluded_types, :methods => :doit do |jp, *args|
|
1291
|
+
aspect = Aspect.new :before, :types => (included_types + excluded_types), exclude_type_sym => excluded_types, :methods => :doit do |jp, obj, *args|
|
1138
1292
|
advice_called = true
|
1139
1293
|
excluded_types.should_not include(jp.target_type)
|
1140
1294
|
end
|
@@ -1151,17 +1305,33 @@ describe Aspect, "#new with a :type(s) parameter and an :exclude_type(s) paramet
|
|
1151
1305
|
aspect.unadvise
|
1152
1306
|
end
|
1153
1307
|
|
1154
|
-
it "should accept :type(s) => [T1, ...], :
|
1308
|
+
it "should accept :type(s) => [T1, ...], :exclude_types => [T2, ...] and exclude join points in the excluded types" do
|
1155
1309
|
do_exclude_types :exclude_types
|
1156
1310
|
end
|
1157
1311
|
|
1158
1312
|
it "should accept :exclude_type as a synonym for :exclude_types" do
|
1159
1313
|
do_exclude_types :exclude_type
|
1160
1314
|
end
|
1315
|
+
|
1316
|
+
it "should accept :type(s) => [T1, ...], :exclude_types_and_ancestors => [T2, ...] and exclude join points in the excluded types" do
|
1317
|
+
do_exclude_types :exclude_types_and_ancestors
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
it "should accept :exclude_type_and_ancestors as a synonym for :exclude_types_and_ancestors" do
|
1321
|
+
do_exclude_types :exclude_type_and_ancestors
|
1322
|
+
end
|
1323
|
+
|
1324
|
+
it "should accept :type(s) => [T1, ...], :exclude_types_and_descendents => [T2, ...] and exclude join points in the excluded types" do
|
1325
|
+
do_exclude_types :exclude_types_and_descendents
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
it "should accept :exclude_type_and_descendents as a synonym for :exclude_types_and_descendents" do
|
1329
|
+
do_exclude_types :exclude_type_and_descendents
|
1330
|
+
end
|
1161
1331
|
end
|
1162
1332
|
|
1163
1333
|
|
1164
|
-
describe Aspect, "
|
1334
|
+
describe Aspect, ".new with a :object(s) parameter and an :exclude_object(s) parameter" do
|
1165
1335
|
def do_exclude_objects exclude_object_sym
|
1166
1336
|
dontExclude1 = DontExclude1.new(1)
|
1167
1337
|
dontExclude2 = DontExclude1.new(2)
|
@@ -1171,9 +1341,9 @@ describe Aspect, "#new with a :object(s) parameter and an :exclude_object(s) par
|
|
1171
1341
|
excluded_objects = [exclude1, exclude2]
|
1172
1342
|
aspect = nil
|
1173
1343
|
advice_called = false
|
1174
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_object_sym => excluded_objects, :methods => :doit do |jp, *args|
|
1344
|
+
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_object_sym => excluded_objects, :methods => :doit do |jp, obj, *args|
|
1175
1345
|
advice_called = true
|
1176
|
-
excluded_objects.should_not include(
|
1346
|
+
excluded_objects.should_not include(obj)
|
1177
1347
|
end
|
1178
1348
|
included_objects.each do |object|
|
1179
1349
|
advice_called = false
|
@@ -1198,7 +1368,7 @@ describe Aspect, "#new with a :object(s) parameter and an :exclude_object(s) par
|
|
1198
1368
|
end
|
1199
1369
|
|
1200
1370
|
|
1201
|
-
describe Aspect, "
|
1371
|
+
describe Aspect, ".new with a :pointcut(s), :type(s), :type(s)_with_ancestors, :type(s)_with_descendents, :object(s), and :method(s) parameter and an :exclude_join_point(s) parameter" do
|
1202
1372
|
def do_exclude_join_points exclude_join_points_sym
|
1203
1373
|
dontExclude1 = DontExclude1.new(1)
|
1204
1374
|
dontExclude2 = DontExclude1.new(2)
|
@@ -1211,9 +1381,9 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1211
1381
|
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1212
1382
|
aspect = nil
|
1213
1383
|
advice_called = false
|
1214
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_join_points_sym => excluded_join_points, :methods => :doit do |jp, *args|
|
1384
|
+
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_join_points_sym => excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1215
1385
|
advice_called = true
|
1216
|
-
excluded_objects.should_not include(
|
1386
|
+
excluded_objects.should_not include(obj)
|
1217
1387
|
end
|
1218
1388
|
|
1219
1389
|
included_objects.each do |object|
|
@@ -1245,7 +1415,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1245
1415
|
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1246
1416
|
aspect = nil
|
1247
1417
|
advice_called = false
|
1248
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_join_points => excluded_join_points, :methods => :doit do |jp, *args|
|
1418
|
+
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_join_points => excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1249
1419
|
advice_called = true
|
1250
1420
|
excluded_types.should_not include(jp.target_type)
|
1251
1421
|
end
|
@@ -1263,6 +1433,42 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1263
1433
|
aspect.unadvise
|
1264
1434
|
end
|
1265
1435
|
|
1436
|
+
it "should accept :type(s)_with_ancestors => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1437
|
+
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1438
|
+
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1439
|
+
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1440
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1441
|
+
aspect = nil
|
1442
|
+
advice_called = false
|
1443
|
+
aspect = Aspect.new :before, :types_and_ancestors => included_types, :exclude_join_points => excluded_join_points, :methods => :doit do |jp, obj, *args|; advice_called = true; end
|
1444
|
+
|
1445
|
+
advice_called = false
|
1446
|
+
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1447
|
+
advice_called.should be_false
|
1448
|
+
advice_called = false
|
1449
|
+
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1450
|
+
advice_called.should be_false
|
1451
|
+
aspect.unadvise
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
it "should accept :type(s)_with_descendents => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1455
|
+
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1456
|
+
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1457
|
+
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1458
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1459
|
+
aspect = nil
|
1460
|
+
advice_called = false
|
1461
|
+
aspect = Aspect.new :before, :types_and_descendents => included_types, :exclude_join_points => excluded_join_points, :methods => :doit do |jp, obj, *args|; advice_called = true; end
|
1462
|
+
|
1463
|
+
advice_called = false
|
1464
|
+
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1465
|
+
advice_called.should be_false
|
1466
|
+
advice_called = false
|
1467
|
+
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1468
|
+
advice_called.should be_false
|
1469
|
+
aspect.unadvise
|
1470
|
+
end
|
1471
|
+
|
1266
1472
|
it "should accept :pointcut(s) => [P1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1267
1473
|
included_types = [DontExclude1, DontExclude2]
|
1268
1474
|
excluded_types = [Exclude1, Exclude2]
|
@@ -1273,7 +1479,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1273
1479
|
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1274
1480
|
aspect = nil
|
1275
1481
|
advice_called = false
|
1276
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_join_points => excluded_join_points do |jp, *args|
|
1482
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_join_points => excluded_join_points do |jp, obj, *args|
|
1277
1483
|
advice_called = true
|
1278
1484
|
excluded_types.should_not include(jp.target_type)
|
1279
1485
|
end
|
@@ -1291,7 +1497,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1291
1497
|
end
|
1292
1498
|
end
|
1293
1499
|
|
1294
|
-
describe Aspect, "
|
1500
|
+
describe Aspect, ".new with a :pointcut(s), :type(s), :object(s), and :method(s) parameter and an :exclude_pointcut(s) parameter" do
|
1295
1501
|
def do_exclude_pointcuts exclude_pointcuts_sym
|
1296
1502
|
dontExclude1 = DontExclude1.new(1)
|
1297
1503
|
dontExclude2 = DontExclude1.new(2)
|
@@ -1304,9 +1510,9 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1304
1510
|
excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1305
1511
|
aspect = nil
|
1306
1512
|
advice_called = false
|
1307
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_pointcuts_sym => excluded_pointcuts, :methods => :doit do |jp, *args|
|
1513
|
+
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_pointcuts_sym => excluded_pointcuts, :methods => :doit do |jp, obj, *args|
|
1308
1514
|
advice_called = true
|
1309
|
-
excluded_objects.should_not include(
|
1515
|
+
excluded_objects.should_not include(obj)
|
1310
1516
|
end
|
1311
1517
|
|
1312
1518
|
included_objects.each do |object|
|
@@ -1338,7 +1544,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1338
1544
|
excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1339
1545
|
aspect = nil
|
1340
1546
|
advice_called = false
|
1341
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_pointcuts => excluded_pointcuts, :methods => :doit do |jp, *args|
|
1547
|
+
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_pointcuts => excluded_pointcuts, :methods => :doit do |jp, obj, *args|
|
1342
1548
|
advice_called = true
|
1343
1549
|
excluded_types.should_not include(jp.target_type)
|
1344
1550
|
end
|
@@ -1366,7 +1572,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1366
1572
|
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1367
1573
|
aspect = nil
|
1368
1574
|
advice_called = false
|
1369
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_pointcuts => excluded_pointcuts do |jp, *args|
|
1575
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_pointcuts => excluded_pointcuts do |jp, obj, *args|
|
1370
1576
|
advice_called = true
|
1371
1577
|
excluded_types.should_not include(jp.target_type)
|
1372
1578
|
end
|
@@ -1384,8 +1590,7 @@ describe Aspect, "#new with a :pointcut(s), :type(s), :object(s), and :method(s)
|
|
1384
1590
|
end
|
1385
1591
|
end
|
1386
1592
|
|
1387
|
-
describe Aspect, "
|
1388
|
-
|
1593
|
+
describe Aspect, ".new with type-based :pointcut(s) and :exclude_type(s) parameter" do
|
1389
1594
|
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s) => [types], where join points with [types] are excluded" do
|
1390
1595
|
included_types = [DontExclude1, DontExclude2]
|
1391
1596
|
excluded_types = [Exclude1, Exclude2]
|
@@ -1393,7 +1598,7 @@ describe Aspect, "#new with type-based :pointcut(s) and :exclude_type(s) paramet
|
|
1393
1598
|
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1394
1599
|
aspect = nil
|
1395
1600
|
advice_called = false
|
1396
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_types => excluded_types do |jp, *args|
|
1601
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_types => excluded_types do |jp, obj, *args|
|
1397
1602
|
advice_called = true
|
1398
1603
|
excluded_types.should_not include(jp.target_type)
|
1399
1604
|
end
|
@@ -1412,8 +1617,36 @@ describe Aspect, "#new with type-based :pointcut(s) and :exclude_type(s) paramet
|
|
1412
1617
|
end
|
1413
1618
|
end
|
1414
1619
|
|
1620
|
+
describe Aspect, ".new with type-based :pointcut(s) and :exclude_type(s)_and_ancestors parameter" do
|
1621
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s)_and_ancestors => [types], where join points with [types] are excluded" do
|
1622
|
+
excluded_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1623
|
+
types = excluded_types + [ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod]
|
1624
|
+
pointcut1 = Pointcut.new :types => types, :method => :all, :method_options => [:exclude_ancestor_methods]
|
1625
|
+
advice_called = false
|
1626
|
+
aspect = Aspect.new :before, :pointcuts => pointcut1, :exclude_types_and_ancestors => excluded_types do |jp, obj, *args|; end
|
1627
|
+
aspect.pointcuts.each do |pc|
|
1628
|
+
pc.join_points_matched.each do |jp|
|
1629
|
+
jp.target_type.should == ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod
|
1630
|
+
end
|
1631
|
+
end
|
1632
|
+
aspect.unadvise
|
1633
|
+
end
|
1634
|
+
end
|
1635
|
+
|
1636
|
+
describe Aspect, ".new with type-based :pointcut(s) and :exclude_type(s)_and_descendents parameter" do
|
1637
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s)_and_descendents => [types], where join points with [types] are excluded" do
|
1638
|
+
excluded_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1639
|
+
types = excluded_types + [ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod]
|
1640
|
+
pointcut1 = Pointcut.new :types => types, :method => :all, :method_options => [:exclude_ancestor_methods]
|
1641
|
+
advice_called = false
|
1642
|
+
aspect = Aspect.new :before, :pointcuts => pointcut1, :exclude_types_and_descendents => excluded_types do |jp, obj, *args|; end
|
1643
|
+
aspect.pointcuts.size.should == 0
|
1644
|
+
aspect.unadvise
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
|
1415
1648
|
|
1416
|
-
describe Aspect, "
|
1649
|
+
describe Aspect, ".new with object-based :pointcut(s) and :exclude_object(s) or :exclude_method(s) parameter" do
|
1417
1650
|
|
1418
1651
|
it "should accept :pointcut(s) => [P1, ...], :exclude_object(s) => [objects], where join points with [objects] are excluded" do
|
1419
1652
|
dontExclude1 = DontExclude1.new(1)
|
@@ -1426,9 +1659,9 @@ describe Aspect, "#new with object-based :pointcut(s) and :exclude_object(s) or
|
|
1426
1659
|
pointcut2 = Pointcut.new :objects => excluded_objects, :method => :doit
|
1427
1660
|
aspect = nil
|
1428
1661
|
advice_called = false
|
1429
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_objects => excluded_objects do |jp, *args|
|
1662
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_objects => excluded_objects do |jp, obj, *args|
|
1430
1663
|
advice_called = true
|
1431
|
-
excluded_objects.should_not include(
|
1664
|
+
excluded_objects.should_not include(obj)
|
1432
1665
|
end
|
1433
1666
|
included_objects.each do |object|
|
1434
1667
|
advice_called = false
|
@@ -1444,7 +1677,7 @@ describe Aspect, "#new with object-based :pointcut(s) and :exclude_object(s) or
|
|
1444
1677
|
end
|
1445
1678
|
end
|
1446
1679
|
|
1447
|
-
describe Aspect, "
|
1680
|
+
describe Aspect, ".new with :method(s) and :exclude_method(s) parameter" do
|
1448
1681
|
before :each do
|
1449
1682
|
@dontExclude1 = DontExclude1.new(1)
|
1450
1683
|
@dontExclude2 = DontExclude1.new(2)
|
@@ -1467,7 +1700,7 @@ describe Aspect, "#new with :method(s) and :exclude_method(s) parameter" do
|
|
1467
1700
|
parameter_hash[:exclude_method] = :doit3
|
1468
1701
|
aspect = nil
|
1469
1702
|
advice_called = false
|
1470
|
-
aspect = Aspect.new parameter_hash do |jp, *args|
|
1703
|
+
aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1471
1704
|
advice_called = true
|
1472
1705
|
@excluded_methods.should_not include(jp.method_name)
|
1473
1706
|
end
|
@@ -1525,7 +1758,7 @@ describe Aspect, "#new with :method(s) and :exclude_method(s) parameter" do
|
|
1525
1758
|
# parameter_hash[:method] = /doit/
|
1526
1759
|
# aspect = nil
|
1527
1760
|
# advice_called = false
|
1528
|
-
# aspect = Aspect.new parameter_hash do |jp, *args|
|
1761
|
+
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1529
1762
|
# advice_called = true
|
1530
1763
|
# @excluded_methods.should_not include(jp.method_name)
|
1531
1764
|
# end
|
@@ -1540,7 +1773,7 @@ describe Aspect, "#new with :method(s) and :exclude_method(s) parameter" do
|
|
1540
1773
|
# def buggy parameter_hash
|
1541
1774
|
# parameter_hash[:before] = ''
|
1542
1775
|
# parameter_hash[:exclude_method] = :doit3
|
1543
|
-
# aspect = Aspect.new parameter_hash do |jp, *args|
|
1776
|
+
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1544
1777
|
# end
|
1545
1778
|
# @excluded_objects.each do |object|
|
1546
1779
|
# object.doit
|