aquarium 0.3.0 → 0.3.1
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/Aquarium.ipr +253 -0
- data/Aquarium.iws +629 -0
- data/CHANGES +43 -0
- data/UPGRADE +13 -7
- data/examples/method_tracing_example_spec.rb +4 -1
- data/lib/aquarium/aspects/aspect.rb +28 -11
- data/lib/aquarium/aspects/exclusion_handler.rb +1 -1
- data/lib/aquarium/aspects/join_point.rb +58 -14
- data/lib/aquarium/aspects/pointcut.rb +5 -6
- data/lib/aquarium/extras/design_by_contract.rb +1 -1
- data/lib/aquarium/finders/method_finder.rb +1 -4
- data/lib/aquarium/finders/type_finder.rb +8 -1
- data/lib/aquarium/utils.rb +1 -0
- data/lib/aquarium/utils/default_logger.rb +20 -0
- data/lib/aquarium/utils/options_utils.rb +74 -12
- data/lib/aquarium/utils/type_utils.rb +1 -7
- data/lib/aquarium/version.rb +1 -1
- data/spec/aquarium/aspects/advice_chain_node_spec.rb +1 -1
- data/spec/aquarium/aspects/advice_spec.rb +1 -1
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +1531 -1465
- data/spec/aquarium/aspects/aspect_spec.rb +22 -27
- data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +1 -1
- data/spec/aquarium/aspects/aspect_with_subtypes_spec.rb +1 -1
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +1 -1
- data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +1 -1
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +434 -424
- data/spec/aquarium/aspects/join_point_spec.rb +27 -4
- data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +98 -102
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +95 -107
- data/spec/aquarium/aspects/pointcut_spec.rb +1365 -1382
- data/spec/aquarium/extensions/hash_spec.rb +1 -1
- data/spec/aquarium/extensions/set_spec.rb +1 -1
- data/spec/aquarium/finders/finder_result_spec.rb +1 -1
- data/spec/aquarium/finders/method_finder_spec.rb +1 -1
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +63 -145
- data/spec/aquarium/{spec_example_classes.rb → spec_example_types.rb} +35 -0
- data/spec/aquarium/utils/default_logger_spec.rb +28 -0
- data/spec/aquarium/utils/hash_utils_spec.rb +1 -1
- data/spec/aquarium/utils/logic_error_spec.rb +1 -1
- data/spec/aquarium/utils/name_utils_spec.rb +1 -1
- data/spec/aquarium/utils/nil_object_spec.rb +1 -1
- data/spec/aquarium/utils/options_utils_spec.rb +122 -0
- data/spec/aquarium/utils/set_utils_spec.rb +1 -1
- metadata +9 -4
@@ -1,15 +1,42 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'aquarium/utils/default_logger'
|
3
|
+
|
1
4
|
module Aquarium
|
2
5
|
module Utils
|
3
6
|
|
4
7
|
# Support parsing and processing of key-value pairs of options.
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# init_type_specific_specification(original_options, options_hash)
|
8
|
+
# Types including this module must define the following methods (see Pointcut for an example):
|
9
|
+
# <tt>all_allowed_option_symbols</tt>
|
10
|
+
# Return an array of all allowed options as symbols.
|
11
|
+
# <tt>init_type_specific_specification(original_options, options_hash)</tt>
|
12
|
+
# Called to perform any final options handling unique for the type (optional).
|
13
|
+
# In addition, including types should have their <tt>initialize</tt> methods calls this module's
|
14
|
+
# <tt>init_specification</tt> to do the options processing.
|
15
|
+
#
|
16
|
+
# This module also defines several universal options that will be available to all types that include this module:
|
17
|
+
# <tt>:logger => options_hash[:logger] || default system-wide Logger</tt>
|
18
|
+
# A standard library Logger used for any messages. A default system-wide logger is used otherwise.
|
19
|
+
# The corresponding <tt>logger</tt> and <tt>logger=</tt> accessors are defined.
|
20
|
+
#
|
21
|
+
# <tt>:logger_stream => options_hash[:logger_stream]</tt>
|
22
|
+
# An an alternative to defining the logger, you can define just the output stream where log output will be written.
|
23
|
+
# If this option is specified, a new logger will be created for the instance with this output stream.
|
24
|
+
# There is no corresponding accessors; use the corresponding methods on the <tt>logger</tt> object instead.
|
25
|
+
#
|
26
|
+
# <tt>:severity => options_hash[:severity]</tt>
|
27
|
+
# The logging severity level, one of the Logger::Severity values or the corresponding integer value.
|
28
|
+
# If this option is specified, a new logger will be created for the instance with this output stream.
|
29
|
+
# There is no corresponding accessors; use the corresponding methods on the <tt>logger</tt> object instead.
|
30
|
+
#
|
31
|
+
# <tt>:noop => options_hash[:noop] || false</tt>
|
32
|
+
# If true, don't do "anything", the interpretation of which will vary with the type receiving the option.
|
33
|
+
# For example, a type might go through some initialization, such as parsng its argument list, but
|
34
|
+
# do nothing after that. Primarily useful for debugging.
|
35
|
+
# The value can be accessed through the <tt>noop</tt> and <tt>noop=</tt> accessors.
|
9
36
|
module OptionsUtils
|
10
37
|
|
11
38
|
def self.universal_options
|
12
|
-
[:
|
39
|
+
[:logger_stream, :logger, :severity, :noop]
|
13
40
|
end
|
14
41
|
|
15
42
|
def init_specification options, canonical_options, &optional_block
|
@@ -26,17 +53,25 @@ module Aquarium
|
|
26
53
|
end
|
27
54
|
@specification[key.intern] = Set.new(make_array(all_related_options))
|
28
55
|
end
|
29
|
-
|
30
|
-
|
31
|
-
:
|
32
|
-
:
|
56
|
+
|
57
|
+
universal_options = {
|
58
|
+
:logger_stream => options_hash[:logger_stream],
|
59
|
+
:severity => options_hash[:severity],
|
60
|
+
:noop => options_hash[:noop] || false
|
33
61
|
}
|
34
|
-
|
62
|
+
|
63
|
+
set_logger_if_logger_or_stream_specified universal_options, options_hash
|
64
|
+
set_logger_severity_if_specified universal_options, options_hash
|
65
|
+
set_logger_if_not_specified universal_options, options_hash
|
66
|
+
|
67
|
+
OptionsUtils::universal_options.each do |uopt|
|
68
|
+
@specification[uopt] = Set.new([universal_options[uopt]]) unless universal_options[uopt].nil?
|
69
|
+
end
|
35
70
|
init_type_specific_specification @original_options, options_hash, &optional_block
|
36
71
|
validate_options options_hash
|
37
72
|
end
|
38
73
|
|
39
|
-
|
74
|
+
[:logger, :noop].each do |name|
|
40
75
|
module_eval(<<-EOF, __FILE__, __LINE__)
|
41
76
|
def #{name}
|
42
77
|
@specification[:#{name}].to_a.first
|
@@ -48,7 +83,7 @@ module Aquarium
|
|
48
83
|
end
|
49
84
|
|
50
85
|
# Override for type-specific initialization
|
51
|
-
def init_type_specific_specification
|
86
|
+
def init_type_specific_specification original_options, options_hash, &optional_block
|
52
87
|
end
|
53
88
|
|
54
89
|
def hashify options
|
@@ -69,6 +104,33 @@ module Aquarium
|
|
69
104
|
raise Aquarium::Utils::InvalidOptions.new("Unknown options specified: #{unknowns.inspect}") if unknowns.size > 0
|
70
105
|
end
|
71
106
|
|
107
|
+
protected
|
108
|
+
|
109
|
+
def set_logger_if_logger_or_stream_specified universal_options, options_hash
|
110
|
+
if not options_hash[:logger].nil?
|
111
|
+
universal_options[:logger] = options_hash[:logger]
|
112
|
+
elsif not options_hash[:logger_stream].nil?
|
113
|
+
universal_options[:logger] = Logger.new options_hash[:logger_stream]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_logger_severity_if_specified universal_options, options_hash
|
118
|
+
unless options_hash[:severity].nil?
|
119
|
+
unless universal_options[:logger].nil?
|
120
|
+
universal_options[:logger].level = options_hash[:severity]
|
121
|
+
else
|
122
|
+
universal_options[:logger] = Logger.new STDERR
|
123
|
+
universal_options[:logger].level = options_hash[:severity]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def set_logger_if_not_specified universal_options, options_hash
|
129
|
+
if universal_options[:logger].nil?
|
130
|
+
universal_options[:logger] = DefaultLogger.logger
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
72
134
|
end
|
73
135
|
end
|
74
136
|
end
|
@@ -21,16 +21,10 @@ module Aquarium
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def self.do_descendents clazz, visiting_module, visited, result
|
24
|
-
# p "#{clazz}, #{visiting_module}<br/>"
|
25
24
|
visited << visiting_module
|
26
|
-
|
27
|
-
# it comes up undefined! However, doing class_eval works around it. Is there a better way??
|
28
|
-
visiting_module.constants.each do |const|
|
25
|
+
visiting_module.constants.each do |const|
|
29
26
|
next unless visiting_module.const_defined?(const)
|
30
27
|
clazz2 = visiting_module.const_get(const)
|
31
|
-
# clazz2 = visiting_module.const_defined?(const) ?
|
32
|
-
# visiting_module.const_get(const) :
|
33
|
-
# visiting_module.class_eval(const)
|
34
28
|
next if visited.include?(clazz2) or not clazz2.respond_to?(:ancestors)
|
35
29
|
visited << clazz2
|
36
30
|
result << clazz2 if clazz2.ancestors.include?(clazz)
|
data/lib/aquarium/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../
|
2
|
+
require File.dirname(__FILE__) + '/../spec_example_types'
|
3
3
|
require 'aquarium/aspects/advice'
|
4
4
|
require 'aquarium/aspects/aspect'
|
5
5
|
include Aquarium::Aspects
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../
|
2
|
+
require File.dirname(__FILE__) + '/../spec_example_types'
|
3
3
|
require 'aquarium/aspects/aspect'
|
4
4
|
require 'aquarium/aspects/dsl'
|
5
5
|
require 'aquarium/utils/array_utils'
|
@@ -44,1169 +44,1194 @@ module Aquarium
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe Aspect, "
|
48
|
-
|
49
|
-
|
47
|
+
describe Aspect, "methods" do
|
48
|
+
include Aquarium::TypeUtilsStub
|
49
|
+
|
50
|
+
before :all do
|
51
|
+
stub_type_utils_descendents
|
50
52
|
end
|
51
|
-
|
52
|
-
|
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)
|
53
|
+
after :all do
|
54
|
+
unstub_type_utils_descendents
|
57
55
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
|
57
|
+
describe Aspect, ".new (the :ignore_no_matching_join_points parameter that specifies whether or not to warn about no join point matches)" do
|
58
|
+
before :each do
|
59
|
+
@log_stream = StringIO.new
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should warn about no join point matches if the :ignore_no_matching_join_points is not specified." do
|
63
|
+
lambda {Aspect.new(:after, :logger_stream => @log_stream) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
64
|
+
@log_stream.string.should_not be_empty
|
65
|
+
end
|
66
|
+
it "should warn about no join point matches if :ignore_no_matching_join_points => false is specified." do
|
67
|
+
lambda {Aspect.new(:after, :logger_stream => @log_stream, :ignore_no_matching_join_points => false) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
68
|
+
@log_stream.string.should_not be_empty
|
69
|
+
end
|
70
|
+
it "should not warn about no join point matches if :ignore_no_matching_join_points => true is specified." do
|
71
|
+
lambda {Aspect.new(:after, :logger_stream => @log_stream, :ignore_no_matching_join_points => true) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
72
|
+
@log_stream.string.should be_empty
|
73
|
+
end
|
63
74
|
end
|
64
75
|
|
65
|
-
|
66
|
-
|
67
|
-
|
76
|
+
describe Aspect, ".new (parameters that specify the kind of advice)" do
|
77
|
+
before :all do
|
78
|
+
@pointcut_opts = {:type => Aquarium::AspectInvocationTestClass}
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should require the kind of advice as the first parameter." do
|
82
|
+
lambda { Aspect.new :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
83
|
+
end
|
68
84
|
|
69
|
-
|
70
|
-
|
71
|
-
|
85
|
+
it "should contain no other advice types if :around advice specified." do
|
86
|
+
lambda { Aspect.new :around, :before, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
87
|
+
lambda { Aspect.new :around, :after, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
88
|
+
lambda { Aspect.new :around, :after_returning, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
89
|
+
lambda { Aspect.new :around, :after_raising, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
90
|
+
end
|
72
91
|
|
73
|
-
|
74
|
-
|
75
|
-
|
92
|
+
it "should allow only one of :after, :after_returning, or :after_raising advice to be specified." do
|
93
|
+
lambda { Aspect.new :after, :after_returning, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
94
|
+
lambda { Aspect.new :after, :after_raising, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
95
|
+
lambda { Aspect.new :after_returning, :after_raising, :pointcut => @pointcut_opts }.should raise_error(Aquarium::Utils::InvalidOptions)
|
96
|
+
end
|
76
97
|
|
77
|
-
|
78
|
-
|
79
|
-
|
98
|
+
it "should allow :before to be specified with :after." do
|
99
|
+
lambda { Aspect.new :before, :after, :pointcut => @pointcut_opts, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should allow :before to be specified with :after_returning." do
|
103
|
+
lambda { Aspect.new :before, :after_returning, :pointcut => @pointcut_opts, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow :before to be specified with :after_raising." do
|
107
|
+
lambda { Aspect.new :before, :after_raising, :pointcut => @pointcut_opts, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should accept a single exception specified with :after_raising." do
|
111
|
+
lambda { Aspect.new :before, :after_raising => Exception, :pointcut => @pointcut_opts, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
112
|
+
end
|
80
113
|
|
81
|
-
|
82
|
-
|
114
|
+
it "should accept a a list of exceptions specified with :after_raising." do
|
115
|
+
lambda { Aspect.new :before, :after_raising => [Exception, String], :pointcut => @pointcut_opts, :noop => true }.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
116
|
+
end
|
83
117
|
end
|
84
|
-
end
|
85
118
|
|
86
|
-
describe Aspect, ".new (parameters that specify pointcuts)" do
|
87
|
-
|
88
|
-
|
89
|
-
|
119
|
+
describe Aspect, ".new (parameters that specify pointcuts)" do
|
120
|
+
before :all do
|
121
|
+
@pointcut_opts = {:type => Aquarium::AspectInvocationTestClass}
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should contain at least one of :method(s), :pointcut(s), :type(s), or :object(s)." do
|
125
|
+
lambda {Aspect.new(:after, :ignore_no_matching_join_points => true) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
126
|
+
end
|
90
127
|
|
91
|
-
|
92
|
-
|
93
|
-
|
128
|
+
it "should contain at least one of :pointcut(s), :type(s), or :object(s) unless :default_objects => object is given." do
|
129
|
+
aspect = Aspect.new(:after, :default_objects => Aquarium::AspectInvocationTestClass.new, :methods => :public_test_method, :noop => true) {|jp, obj, *args| true}
|
130
|
+
end
|
131
|
+
|
132
|
+
Aspect::CANONICAL_OPTIONS["default_objects"].each do |key|
|
133
|
+
it "should accept :#{key} as a synonym for :default_objects." do
|
134
|
+
aspect = Aspect.new(:after, key.intern => Aquarium::AspectInvocationTestClass.new, :methods => :public_test_method, :noop => true) {|jp, obj, *args| true}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not contain :pointcut(s) and either :type(s) or :object(s)." do
|
139
|
+
lambda {Aspect.new(:after, :pointcuts => @pointcut_opts, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
140
|
+
lambda {Aspect.new(:after, :pointcuts => @pointcut_opts, :object => Aquarium::AspectInvocationTestClass.new, :methods => :public_test_method) {|jp, obj, *args| true}}.should raise_error(Aquarium::Utils::InvalidOptions)
|
141
|
+
end
|
94
142
|
end
|
95
143
|
|
96
|
-
|
97
|
-
|
98
|
-
|
144
|
+
|
145
|
+
describe Aspect, ".new with :types parameter" do
|
146
|
+
it "should advise the specified types." do
|
147
|
+
@advice_called = false
|
148
|
+
aspect = Aspect.new :before, :types => Aquarium::AspectInvocationTestClass, :method => :public_test_method do; @advice_called = true; end
|
149
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method
|
99
150
|
aspect.unadvise
|
151
|
+
@advice_called.should be_true
|
152
|
+
end
|
153
|
+
|
154
|
+
Aspect::CANONICAL_OPTIONS["types"].each do |key|
|
155
|
+
it "should accept :#{key} as a synonym for :types." do
|
156
|
+
lambda { Aspect.new :before, key.intern => Aquarium::AspectInvocationTestClass, :method => :public_test_method, :noop => true do; end }.should_not raise_error
|
157
|
+
end
|
100
158
|
end
|
101
159
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
160
|
+
|
161
|
+
describe Aspect, ".new with :pointcuts parameter" do
|
162
|
+
it "should advise the specified pointcuts." do
|
163
|
+
@advice_called = false
|
164
|
+
aspect = Aspect.new :before, :pointcuts => {:types => Aquarium::AspectInvocationTestClass, :method => :public_test_method} do; @advice_called = true; end
|
165
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method
|
166
|
+
aspect.unadvise
|
167
|
+
@advice_called.should be_true
|
168
|
+
end
|
169
|
+
|
170
|
+
Aspect::CANONICAL_OPTIONS["pointcuts"].each do |key|
|
171
|
+
it "should accept :#{key} as a synonym for :pointcuts." do
|
172
|
+
lambda { Aspect.new :before, key.intern => {:type => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, :noop => true do; end }.should_not raise_error
|
173
|
+
end
|
174
|
+
end
|
106
175
|
end
|
107
|
-
end
|
108
176
|
|
177
|
+
describe Aspect, ".new with :objects parameter" do
|
178
|
+
it "should advise the specified objects." do
|
179
|
+
@advice_called = false
|
180
|
+
object = Aquarium::AspectInvocationTestClass.new
|
181
|
+
aspect = Aspect.new :before, :objects => object, :method => :public_test_method do; @advice_called = true; end
|
182
|
+
object.public_test_method
|
183
|
+
aspect.unadvise
|
184
|
+
@advice_called.should be_true
|
185
|
+
end
|
109
186
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
aspect1 = Aspect.new :before, key.intern => Aquarium::AspectInvocationTestClass, :method => @expected_methods, :advice => @advice
|
116
|
-
aspect2 = Aspect.new :before, :types => Aquarium::AspectInvocationTestClass, :method => @expected_methods, :advice => @advice
|
117
|
-
aspects_should_be_equal 1, aspect1, aspect2
|
118
|
-
aspect1.unadvise
|
119
|
-
aspect2.unadvise
|
187
|
+
Aspect::CANONICAL_OPTIONS["objects"].each do |key|
|
188
|
+
it "should accept :#{key} as a synonym for :objects." do
|
189
|
+
object = Aquarium::AspectInvocationTestClass.new
|
190
|
+
lambda { Aspect.new :before, key.intern => object, :method => :public_test_method, :noop => true do; end }.should_not raise_error
|
191
|
+
end
|
120
192
|
end
|
121
193
|
end
|
122
|
-
end
|
123
194
|
|
124
|
-
describe Aspect, ".new
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
195
|
+
describe Aspect, ".new with :methods parameter" do
|
196
|
+
it "should advise the specified methods." do
|
197
|
+
@advice_called = false
|
198
|
+
aspect = Aspect.new :before, :types => Aquarium::AspectInvocationTestClass, :methods => :public_test_method do; @advice_called = true; end
|
199
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method
|
200
|
+
aspect.unadvise
|
201
|
+
@advice_called.should be_true
|
202
|
+
end
|
203
|
+
|
204
|
+
Aspect::CANONICAL_OPTIONS["methods"].each do |key|
|
205
|
+
it "should accept :#{key} as a synonym for :methods." do
|
206
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, key.intern => :public_test_method, :noop => true do; end }.should_not raise_error
|
207
|
+
end
|
134
208
|
end
|
135
209
|
end
|
136
|
-
end
|
137
210
|
|
138
|
-
describe Aspect, ".new (:
|
139
|
-
|
140
|
-
|
211
|
+
describe Aspect, ".new (:attributes parameter)" do
|
212
|
+
Aspect::CANONICAL_OPTIONS["attributes"].each do |key|
|
213
|
+
it "should accept :#{key} as a synonym for :attributes." do
|
214
|
+
@advice_called = false
|
215
|
+
aspect = Aspect.new :before, :types => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args do; @advice_called = true; end
|
216
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method_args
|
217
|
+
aspect.unadvise
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should accept :reading => ... as a synonym for :attributes => ..., :attribute_options => [:readers]." do
|
141
222
|
@advice = Proc.new {}
|
142
|
-
@expected_methods = [:
|
143
|
-
|
144
|
-
|
145
|
-
aspect2 = Aspect.new :before, :objects => object, :method => @expected_methods, :advice => @advice
|
223
|
+
@expected_methods = [:public_test_method_args]
|
224
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :reading => :public_test_method_args, :advice => @advice
|
225
|
+
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args, :attribute_options => [:readers], :advice => @advice
|
146
226
|
aspects_should_be_equal 1, aspect1, aspect2
|
147
227
|
aspect1.unadvise
|
148
228
|
aspect2.unadvise
|
149
229
|
end
|
150
|
-
end
|
151
|
-
end
|
152
230
|
|
153
|
-
|
154
|
-
Aspect::CANONICAL_OPTIONS["methods"].each do |key|
|
155
|
-
it "should accept :#{key} as a synonym for :methods." do
|
231
|
+
it "should accept :writing => ... as a synonym for :attributes => ..., :attribute_options => [:writer]." do
|
156
232
|
@advice = Proc.new {}
|
157
|
-
@expected_methods = [:
|
158
|
-
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass,
|
159
|
-
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :
|
233
|
+
@expected_methods = [:public_test_method_args=]
|
234
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :writing => :public_test_method_args, :advice => @advice
|
235
|
+
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args, :attribute_options => [:writers], :advice => @advice
|
160
236
|
aspects_should_be_equal 1, aspect1, aspect2
|
161
237
|
aspect1.unadvise
|
162
238
|
aspect2.unadvise
|
163
239
|
end
|
164
|
-
end
|
165
|
-
end
|
166
240
|
|
167
|
-
|
168
|
-
Aspect::CANONICAL_OPTIONS["attributes"].each do |key|
|
169
|
-
it "should accept :#{key} as a synonym for :attributes." do
|
241
|
+
it "should accept :changing => ... as a synonym for :attributes => ..., :attribute_options => [:writer]." do
|
170
242
|
@advice = Proc.new {}
|
171
|
-
@expected_methods = [:public_test_method_args
|
172
|
-
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass,
|
173
|
-
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes =>
|
174
|
-
aspects_should_be_equal
|
243
|
+
@expected_methods = [:public_test_method_args=]
|
244
|
+
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :changing => :public_test_method_args, :advice => @advice
|
245
|
+
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args, :attribute_options => [:writers], :advice => @advice
|
246
|
+
aspects_should_be_equal 1, aspect1, aspect2
|
175
247
|
aspect1.unadvise
|
176
248
|
aspect2.unadvise
|
177
249
|
end
|
178
250
|
end
|
179
251
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
aspect2.unadvise
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should accept :writing => ... as a synonym for :attributes => ..., :attribute_options => [:writer]." do
|
191
|
-
@advice = Proc.new {}
|
192
|
-
@expected_methods = [:public_test_method_args=]
|
193
|
-
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :writing => :public_test_method_args, :advice => @advice
|
194
|
-
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args, :attribute_options => [:writers], :advice => @advice
|
195
|
-
aspects_should_be_equal 1, aspect1, aspect2
|
196
|
-
aspect1.unadvise
|
197
|
-
aspect2.unadvise
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should accept :changing => ... as a synonym for :attributes => ..., :attribute_options => [:writer]." do
|
201
|
-
@advice = Proc.new {}
|
202
|
-
@expected_methods = [:public_test_method_args=]
|
203
|
-
aspect1 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :changing => :public_test_method_args, :advice => @advice
|
204
|
-
aspect2 = Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :attributes => :public_test_method_args, :attribute_options => [:writers], :advice => @advice
|
205
|
-
aspects_should_be_equal 1, aspect1, aspect2
|
206
|
-
aspect1.unadvise
|
207
|
-
aspect2.unadvise
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe Aspect, ".new (with a :type(s) parameter and a :method(s) parameter)" do
|
212
|
-
before :each do
|
213
|
-
@protection = 'public'
|
214
|
-
@are_class_methods = false
|
215
|
-
@types_option = :types
|
216
|
-
@method_options = []
|
217
|
-
end
|
252
|
+
describe Aspect, ".new (with a :type(s) parameter and a :method(s) parameter)" do
|
253
|
+
before :each do
|
254
|
+
@protection = 'public'
|
255
|
+
@are_class_methods = false
|
256
|
+
@types_option = :types
|
257
|
+
@method_options = []
|
258
|
+
end
|
218
259
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
it "should accept :type(s) => [T1, ...], :methods => [m, ...]" do
|
238
|
-
@type_spec = [Aquarium::AspectInvocationTestClass]
|
239
|
-
@method_spec = [:public_test_method]
|
240
|
-
do_type_spec
|
241
|
-
end
|
260
|
+
def do_type_spec
|
261
|
+
aspect = nil
|
262
|
+
advice_called = false
|
263
|
+
aspect = Aspect.new :before, @types_option => @type_spec, :methods => @method_spec, :method_options => @method_options do |jp, obj, *args|
|
264
|
+
advice_called = true
|
265
|
+
jp.should_not be_nil
|
266
|
+
args.size.should == 4
|
267
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
268
|
+
end
|
269
|
+
if @are_class_methods
|
270
|
+
Aquarium::AspectInvocationTestClass.method("#{@protection}_class_test_method").call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
271
|
+
else
|
272
|
+
Aquarium::AspectInvocationTestClass.new.method("#{@protection}_test_method").call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
273
|
+
end
|
274
|
+
advice_called.should be_true
|
275
|
+
aspect.unadvise
|
276
|
+
end
|
242
277
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
end
|
278
|
+
it "should accept :type(s) => T1, :methods => m" do
|
279
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
280
|
+
@method_spec = :public_test_method
|
281
|
+
do_type_spec
|
282
|
+
end
|
249
283
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
end
|
284
|
+
it "should accept :type(s) => T1, :methods => [m, ...]" do
|
285
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
286
|
+
@method_spec = [:public_test_method]
|
287
|
+
do_type_spec
|
288
|
+
end
|
256
289
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
290
|
+
it "should accept :type(s) => T1, :methods => /m/" do
|
291
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
292
|
+
@method_spec = /test_method/
|
293
|
+
do_type_spec
|
294
|
+
end
|
262
295
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
296
|
+
it "should accept :type(s) => [T1, ...], :methods => m" do
|
297
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
298
|
+
@method_spec = :public_test_method
|
299
|
+
do_type_spec
|
300
|
+
end
|
268
301
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
302
|
+
it "should accept :type(s) => [T1, ...], :methods => [m, ...]" do
|
303
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
304
|
+
@method_spec = [:public_test_method]
|
305
|
+
do_type_spec
|
306
|
+
end
|
274
307
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
end
|
308
|
+
it "should accept :type(s) => [T1, ...], :methods => /m/" do
|
309
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
310
|
+
@method_spec = /test_method/
|
311
|
+
do_type_spec
|
312
|
+
end
|
281
313
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
end
|
314
|
+
it "should accept :type(s) => /T1/, :methods => m" do
|
315
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
316
|
+
@method_spec = :public_test_method
|
317
|
+
do_type_spec
|
318
|
+
end
|
288
319
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
320
|
+
it "should accept :type(s) => /T1/, :methods => [m, ...]" do
|
321
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
322
|
+
@method_spec = [:public_test_method]
|
323
|
+
do_type_spec
|
324
|
+
end
|
294
325
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
326
|
+
it "should accept :type(s) => /T1/, :methods => /m/" do
|
327
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
328
|
+
@method_spec = /test_method/
|
329
|
+
do_type_spec
|
330
|
+
end
|
300
331
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
332
|
+
it "should accept :type(s)_and_ancestors => T1, :methods => [m, ...]" do
|
333
|
+
@types_option = :types_and_ancestors
|
334
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
335
|
+
@method_spec = [:public_test_method]
|
336
|
+
do_type_spec
|
337
|
+
end
|
306
338
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
339
|
+
it "should accept :type(s)_and_ancestors => [T1, ...], :methods => [m, ...]" do
|
340
|
+
@types_option = :types_and_ancestors
|
341
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
342
|
+
@method_spec = [:public_test_method]
|
343
|
+
do_type_spec
|
344
|
+
end
|
313
345
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
346
|
+
it "should accept :type(s)_and_ancestors => /T1/, :methods => [m, ...]" do
|
347
|
+
@types_option = :types_and_ancestors
|
348
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
349
|
+
@method_spec = [:public_test_method]
|
350
|
+
do_type_spec
|
351
|
+
end
|
320
352
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
353
|
+
it "should accept :type(s)_and_descendents => T1, :methods => [m, ...]" do
|
354
|
+
@types_option = :types_and_descendents
|
355
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
356
|
+
@method_spec = [:public_test_method]
|
357
|
+
do_type_spec
|
358
|
+
end
|
326
359
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
360
|
+
it "should accept :type(s)_and_descendents => [T1, ...], :methods => [m, ...]" do
|
361
|
+
@types_option = :types_and_descendents
|
362
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
363
|
+
@method_spec = [:public_test_method]
|
364
|
+
do_type_spec
|
365
|
+
end
|
332
366
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
367
|
+
it "should accept :type(s)_and_descendents => /T1/, :methods => [m, ...]" do
|
368
|
+
@types_option = :types_and_descendents
|
369
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
370
|
+
@method_spec = [:public_test_method]
|
371
|
+
do_type_spec
|
372
|
+
end
|
339
373
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
374
|
+
it "should accept :type(s) => ..., :methods => ..., :method_options => [:exclude_ancestor_methods] to exclude methods defined in ancestors" do
|
375
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
376
|
+
@method_spec = /test_method/
|
377
|
+
@method_options = [:exclude_ancestor_methods]
|
378
|
+
do_type_spec
|
379
|
+
end
|
346
380
|
|
347
|
-
|
348
|
-
it "should accept :type(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
381
|
+
it "should accept :type(s) => ..., :methods => ..., :method_options => [:instance, :public] to match only instance and public (both are the defaults) methods" do
|
349
382
|
@type_spec = /Aquarium::AspectInvocationTestClass/
|
350
383
|
@method_spec = /test_method/
|
351
|
-
@method_options = [
|
352
|
-
@protection = protection
|
384
|
+
@method_options = [:instance, :public]
|
353
385
|
do_type_spec
|
354
386
|
end
|
355
|
-
end
|
356
387
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
388
|
+
%w[public protected private].each do |protection|
|
389
|
+
it "should accept :type(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
390
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
391
|
+
@method_spec = /test_method/
|
392
|
+
@method_options = [protection.intern]
|
393
|
+
@protection = protection
|
394
|
+
do_type_spec
|
395
|
+
end
|
396
|
+
end
|
364
397
|
|
365
|
-
|
366
|
-
it "should accept :type(s) => ..., :methods => ..., :method_options => [:class, :#{protection.intern}] to match only class #{protection} methods" do
|
398
|
+
it "should accept :type(s) => ..., :methods => ..., :method_options => [:class] to match only public (default) class methods" do
|
367
399
|
@type_spec = /Aquarium::AspectInvocationTestClass/
|
368
400
|
@method_spec = /test_method/
|
369
|
-
@method_options = [:class
|
370
|
-
@protection = protection
|
401
|
+
@method_options = [:class]
|
371
402
|
@are_class_methods = true
|
372
403
|
do_type_spec
|
373
404
|
end
|
405
|
+
|
406
|
+
%w[public private].each do |protection|
|
407
|
+
it "should accept :type(s) => ..., :methods => ..., :method_options => [:class, :#{protection.intern}] to match only class #{protection} methods" do
|
408
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
409
|
+
@method_spec = /test_method/
|
410
|
+
@method_options = [:class, protection.intern]
|
411
|
+
@protection = protection
|
412
|
+
@are_class_methods = true
|
413
|
+
do_type_spec
|
414
|
+
end
|
415
|
+
end
|
374
416
|
end
|
375
|
-
end
|
376
417
|
|
377
418
|
|
378
|
-
describe Aspect, ".new (with a :type(s) parameter and a :attribute(s) parameter)" do
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
419
|
+
describe Aspect, ".new (with a :type(s) parameter and a :attribute(s) parameter)" do
|
420
|
+
before :each do
|
421
|
+
@protection = 'public'
|
422
|
+
@attribute_options = []
|
423
|
+
@are_class_methods = false
|
424
|
+
end
|
384
425
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
426
|
+
def do_type_attribute_spec
|
427
|
+
aspect = nil
|
428
|
+
advice_called = false
|
429
|
+
aspect = Aspect.new :before, :types => @type_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, obj, *args|
|
430
|
+
advice_called = true
|
431
|
+
jp.should_not be_nil
|
432
|
+
expected_args = make_array(@expected_args)
|
433
|
+
args.should == expected_args
|
434
|
+
args.size.should == expected_args.size
|
435
|
+
end
|
436
|
+
object = Aquarium::AspectInvocationTestClass.new
|
437
|
+
@expected_args = nil
|
438
|
+
object.method("#{@protection}_test_method_args".intern).call
|
439
|
+
@expected_args = :a1
|
440
|
+
object.method("#{@protection}_test_method_args=".intern).call @expected_args
|
441
|
+
advice_called.should be_true
|
442
|
+
aspect.unadvise
|
443
|
+
end
|
403
444
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
445
|
+
it "should accept :type(s) => [T1, ...], :attribute(s) => [a, ...]" do
|
446
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
447
|
+
@attribute_spec = [:public_test_method_args]
|
448
|
+
do_type_attribute_spec
|
449
|
+
end
|
409
450
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
451
|
+
it "should accept :type(s) => [T1, ...], :attribute(s) => a" do
|
452
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
453
|
+
@attribute_spec = :public_test_method_args
|
454
|
+
do_type_attribute_spec
|
455
|
+
end
|
415
456
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
457
|
+
it "should accept :type(s) => [T1, ...], :attribute(s) => /a/" do
|
458
|
+
@type_spec = [Aquarium::AspectInvocationTestClass]
|
459
|
+
@attribute_spec = /test_method_args/
|
460
|
+
do_type_attribute_spec
|
461
|
+
end
|
421
462
|
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
463
|
+
it "should accept :type(s) => T1, :attribute(s) => [a]" do
|
464
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
465
|
+
@attribute_spec = [:public_test_method_args]
|
466
|
+
do_type_attribute_spec
|
467
|
+
end
|
427
468
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
469
|
+
it "should accept :type(s) => T1, :attribute(s) => a" do
|
470
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
471
|
+
@attribute_spec = :public_test_method_args
|
472
|
+
do_type_attribute_spec
|
473
|
+
end
|
433
474
|
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
475
|
+
it "should accept :type(s) => T1, :attribute(s) => /a/" do
|
476
|
+
@type_spec = Aquarium::AspectInvocationTestClass
|
477
|
+
@attribute_spec = /test_method_args/
|
478
|
+
do_type_attribute_spec
|
479
|
+
end
|
439
480
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
481
|
+
it "should accept :type(s) => /T1/, :attribute(s) => [a, ...]" do
|
482
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
483
|
+
@attribute_spec = [:public_test_method_args]
|
484
|
+
do_type_attribute_spec
|
485
|
+
end
|
445
486
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
487
|
+
it "should accept :type(s) => /T1/, :attribute(s) => a" do
|
488
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
489
|
+
@attribute_spec = :public_test_method_args
|
490
|
+
do_type_attribute_spec
|
491
|
+
end
|
451
492
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
493
|
+
it "should accept :type(s) => /T1/, :attribute(s) => a" do
|
494
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
495
|
+
@attribute_spec = /test_method_args/
|
496
|
+
do_type_attribute_spec
|
497
|
+
end
|
457
498
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
499
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:readers, :writers] to include both attribute reader and writer methods (default)" do
|
500
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
501
|
+
@attribute_spec = /test_method_args/
|
502
|
+
@attribute_options = [:readers, :writers]
|
503
|
+
do_type_attribute_spec
|
504
|
+
end
|
464
505
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
506
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:readers] to include only attribute reader methods" do
|
507
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
508
|
+
@attribute_spec = /test_method_args/
|
509
|
+
@attribute_options = [:readers]
|
510
|
+
do_type_attribute_spec
|
511
|
+
end
|
471
512
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
513
|
+
it "should accept attribute option :reader as a synonym for :readers" do
|
514
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
515
|
+
@attribute_spec = /test_method_args/
|
516
|
+
@attribute_options = [:reader]
|
517
|
+
do_type_attribute_spec
|
518
|
+
end
|
478
519
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
520
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:writers] to include only attribute writer methods" do
|
521
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
522
|
+
@attribute_spec = /test_method_args/
|
523
|
+
@attribute_options = [:writers]
|
524
|
+
do_type_attribute_spec
|
525
|
+
end
|
485
526
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
527
|
+
it "should accept attribute option :writer as a synonym for :writers" do
|
528
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
529
|
+
@attribute_spec = /test_method_args/
|
530
|
+
@attribute_options = [:writer]
|
531
|
+
do_type_attribute_spec
|
532
|
+
end
|
492
533
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
534
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :readers, :writers] to include both attribute reader and writer methods (default) for class methods" do
|
535
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
536
|
+
@attribute_spec = /test_method_args/
|
537
|
+
@attribute_options = [:class, :readers, :writers]
|
538
|
+
do_type_attribute_spec
|
539
|
+
end
|
499
540
|
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
541
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :readers] to include only attribute reader class methods" do
|
542
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
543
|
+
@attribute_spec = /test_method_args/
|
544
|
+
@attribute_options = [:class, :readers]
|
545
|
+
do_type_attribute_spec
|
546
|
+
end
|
506
547
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
548
|
+
it "should accept :type(s) => ..., :attributes => ..., :attribute_options => [:class, :writers] to include only attribute writer class methods" do
|
549
|
+
@type_spec = /Aquarium::AspectInvocationTestClass/
|
550
|
+
@attribute_spec = /test_method_args/
|
551
|
+
@attribute_options = [:class, :writers]
|
552
|
+
do_type_attribute_spec
|
553
|
+
end
|
512
554
|
end
|
513
|
-
end
|
514
555
|
|
515
|
-
describe Aspect, ".new (with a :object(s) parameter and a :method(s) parameter)" do
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
556
|
+
describe Aspect, ".new (with a :object(s) parameter and a :method(s) parameter)" do
|
557
|
+
before :each do
|
558
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
559
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
560
|
+
@protection = 'public'
|
561
|
+
@method_options = []
|
562
|
+
end
|
522
563
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
it "should accept :object(s) => [o1, ...], :methods => [m, ...]" do
|
539
|
-
@object_spec = [@object1, @object2]
|
540
|
-
@method_spec = [:public_test_method]
|
541
|
-
do_object_spec
|
542
|
-
end
|
543
|
-
|
544
|
-
it "should accept :object(s) => [o1, ...], :methods => m" do
|
545
|
-
@object_spec = [@object1, @object2]
|
546
|
-
@method_spec = :public_test_method
|
547
|
-
do_object_spec
|
548
|
-
end
|
564
|
+
def do_object_spec
|
565
|
+
aspect = nil
|
566
|
+
advice_called = false
|
567
|
+
aspect = Aspect.new :before, :objects => @object_spec, :methods => @method_spec, :method_options => @method_options do |jp, obj, *args|
|
568
|
+
advice_called = true
|
569
|
+
jp.should_not be_nil
|
570
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
571
|
+
end
|
572
|
+
make_array(@object_spec).each do |object|
|
573
|
+
object.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
574
|
+
end
|
575
|
+
advice_called.should be_true
|
576
|
+
aspect.unadvise
|
577
|
+
end
|
549
578
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
579
|
+
it "should accept :object(s) => [o1, ...], :methods => [m, ...]" do
|
580
|
+
@object_spec = [@object1, @object2]
|
581
|
+
@method_spec = [:public_test_method]
|
582
|
+
do_object_spec
|
583
|
+
end
|
555
584
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
585
|
+
it "should accept :object(s) => [o1, ...], :methods => m" do
|
586
|
+
@object_spec = [@object1, @object2]
|
587
|
+
@method_spec = :public_test_method
|
588
|
+
do_object_spec
|
589
|
+
end
|
561
590
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
591
|
+
it "should accept :object(s) => [o1, ...], :methods => /m/" do
|
592
|
+
@object_spec = [@object1, @object2]
|
593
|
+
@method_spec = /test_method/
|
594
|
+
do_object_spec
|
595
|
+
end
|
567
596
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
597
|
+
it "should accept :object(s) => o1, :methods => [m, ...]" do
|
598
|
+
@object_spec = @object1
|
599
|
+
@method_spec = [:public_test_method]
|
600
|
+
do_object_spec
|
601
|
+
end
|
573
602
|
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
end
|
603
|
+
it "should accept :object(s) => o1, :methods => m" do
|
604
|
+
@object_spec = @object1
|
605
|
+
@method_spec = :public_test_method
|
606
|
+
do_object_spec
|
607
|
+
end
|
580
608
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
end
|
609
|
+
it "should accept :object(s) => o1, :methods => /m/" do
|
610
|
+
@object_spec = @object1
|
611
|
+
@method_spec = /test_method/
|
612
|
+
do_object_spec
|
613
|
+
end
|
587
614
|
|
588
|
-
|
589
|
-
it "should accept :object(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
615
|
+
it "should accept :object(s) => ..., :methods => ..., :method_options => [:exclude_ancestor_methods] to exclude methods defined in ancestors" do
|
590
616
|
@object_spec = @object1
|
591
617
|
@method_spec = /test_method/
|
592
|
-
@method_options = [
|
593
|
-
@protection = protection
|
618
|
+
@method_options = [:exclude_ancestor_methods]
|
594
619
|
do_object_spec
|
595
620
|
end
|
596
621
|
|
597
|
-
it "should accept :object(s) => ..., :methods => ..., :method_options => [:instance,
|
622
|
+
it "should accept :object(s) => ..., :methods => ..., :method_options => [:instance, :public] to match only instance and public (both are the defaults) methods" do
|
598
623
|
@object_spec = @object1
|
599
624
|
@method_spec = /test_method/
|
600
|
-
@method_options = [:instance,
|
601
|
-
@protection = protection
|
625
|
+
@method_options = [:instance, :public]
|
602
626
|
do_object_spec
|
603
627
|
end
|
604
|
-
end
|
605
|
-
end
|
606
628
|
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
629
|
+
%w[public protected private].each do |protection|
|
630
|
+
it "should accept :object(s) => ..., :methods => ..., :method_options => [#{protection.intern}] to match only instance (default) #{protection} methods" do
|
631
|
+
@object_spec = @object1
|
632
|
+
@method_spec = /test_method/
|
633
|
+
@method_options = [protection.intern]
|
634
|
+
@protection = protection
|
635
|
+
do_object_spec
|
636
|
+
end
|
637
|
+
|
638
|
+
it "should accept :object(s) => ..., :methods => ..., :method_options => [:instance, #{protection.intern}] to match only instance #{protection} methods" do
|
639
|
+
@object_spec = @object1
|
640
|
+
@method_spec = /test_method/
|
641
|
+
@method_options = [:instance, protection.intern]
|
642
|
+
@protection = protection
|
643
|
+
do_object_spec
|
644
|
+
end
|
645
|
+
end
|
613
646
|
end
|
647
|
+
|
648
|
+
describe Aspect, ".new (with a :object(s) parameter and a :attribute(s) parameter)" do
|
649
|
+
before :each do
|
650
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
651
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
652
|
+
@protection = 'public'
|
653
|
+
@attribute_options = []
|
654
|
+
end
|
614
655
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
656
|
+
def do_object_attribute_spec
|
657
|
+
aspect = nil
|
658
|
+
advice_called = false
|
659
|
+
aspect = Aspect.new :before, :objects => @object_spec, :attributes => @attribute_spec, :attribute_options => @attribute_options do |jp, obj, *args|
|
660
|
+
advice_called = true
|
661
|
+
jp.should_not be_nil
|
662
|
+
expected_args = make_array(@expected_args)
|
663
|
+
args.should == expected_args
|
664
|
+
args.size.should == expected_args.size
|
665
|
+
end
|
666
|
+
make_array(@object_spec).each do |object|
|
667
|
+
@expected_args = nil
|
668
|
+
object.method("#{@protection}_test_method_args".intern).call
|
669
|
+
@expected_args = :a1
|
670
|
+
object.method("#{@protection}_test_method_args=".intern).call @expected_args
|
671
|
+
advice_called.should be_true
|
672
|
+
end
|
673
|
+
aspect.unadvise
|
631
674
|
end
|
632
|
-
aspect.unadvise
|
633
|
-
end
|
634
675
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
676
|
+
it "should accept :object(s) => [T1, ...], :attribute(s) => [a, ...]" do
|
677
|
+
@object_spec = [@object1, @object2]
|
678
|
+
@attribute_spec = [:public_test_method_args]
|
679
|
+
do_object_attribute_spec
|
680
|
+
end
|
640
681
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
682
|
+
it "should accept :object(s) => [T1, ...], :attribute(s) => a" do
|
683
|
+
@object_spec = [@object1, @object2]
|
684
|
+
@attribute_spec = :public_test_method_args
|
685
|
+
do_object_attribute_spec
|
686
|
+
end
|
646
687
|
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
688
|
+
it "should accept :object(s) => [T1, ...], :attribute(s) => /a/" do
|
689
|
+
@object_spec = [@object1, @object2]
|
690
|
+
@attribute_spec = /test_method_args/
|
691
|
+
do_object_attribute_spec
|
692
|
+
end
|
652
693
|
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
694
|
+
it "should accept :object(s) => T1, :attribute(s) => [a]" do
|
695
|
+
@object_spec = @object1
|
696
|
+
@attribute_spec = [:public_test_method_args]
|
697
|
+
do_object_attribute_spec
|
698
|
+
end
|
658
699
|
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
700
|
+
it "should accept :object(s) => T1, :attribute(s) => a" do
|
701
|
+
@object_spec = @object1
|
702
|
+
@attribute_spec = :public_test_method_args
|
703
|
+
do_object_attribute_spec
|
704
|
+
end
|
664
705
|
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
706
|
+
it "should accept :object(s) => T1, :attribute(s) => /a/" do
|
707
|
+
@object_spec = @object1
|
708
|
+
@attribute_spec = /test_method_args/
|
709
|
+
do_object_attribute_spec
|
710
|
+
end
|
670
711
|
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
712
|
+
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:readers, :writers] to include both attribute reader and writer methods (default)" do
|
713
|
+
@object_spec = @object1
|
714
|
+
@attribute_spec = /test_method_args/
|
715
|
+
@attribute_options = [:readers, :writers]
|
716
|
+
do_object_attribute_spec
|
717
|
+
end
|
677
718
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
719
|
+
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:readers] to include only attribute reader methods" do
|
720
|
+
@object_spec = @object1
|
721
|
+
@attribute_spec = /test_method_args/
|
722
|
+
@attribute_options = [:readers]
|
723
|
+
do_object_attribute_spec
|
724
|
+
end
|
684
725
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
726
|
+
it "should accept attribute option :reader as a synonym for :readers" do
|
727
|
+
@object_spec = @object1
|
728
|
+
@attribute_spec = /test_method_args/
|
729
|
+
@attribute_options = [:reader]
|
730
|
+
do_object_attribute_spec
|
731
|
+
end
|
691
732
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
733
|
+
it "should accept :object(s) => ..., :attributes => ..., :attribute_options => [:writers] to include only attribute writer methods" do
|
734
|
+
@object_spec = @object1
|
735
|
+
@attribute_spec = /test_method_args/
|
736
|
+
@attribute_options = [:writers]
|
737
|
+
do_object_attribute_spec
|
738
|
+
end
|
698
739
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
740
|
+
it "should accept attribute option :writer as a synonym for :writers" do
|
741
|
+
@object_spec = @object1
|
742
|
+
@attribute_spec = /test_method_args/
|
743
|
+
@attribute_options = [:writer]
|
744
|
+
do_object_attribute_spec
|
745
|
+
end
|
704
746
|
end
|
705
|
-
end
|
706
747
|
|
707
|
-
describe Aspect, ".new (with a :pointcut parameter taking a hash with type specifications)" do
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
748
|
+
describe Aspect, ".new (with a :pointcut parameter taking a hash with type specifications)" do
|
749
|
+
before :each do
|
750
|
+
@protection = 'public'
|
751
|
+
@are_class_methods = false
|
752
|
+
end
|
712
753
|
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
754
|
+
def do_type_pointcut_spec
|
755
|
+
aspect = nil
|
756
|
+
advice_called = false
|
757
|
+
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, obj, *args|
|
758
|
+
advice_called = true
|
759
|
+
jp.should_not be_nil
|
760
|
+
args.size.should == 4
|
761
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
762
|
+
end
|
763
|
+
if @are_class_methods
|
764
|
+
Aquarium::AspectInvocationTestClass.method("#{@protection}_class_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
765
|
+
else
|
766
|
+
Aquarium::AspectInvocationTestClass.new.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
767
|
+
end
|
768
|
+
advice_called.should be_true
|
769
|
+
aspect.unadvise
|
770
|
+
end
|
730
771
|
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
772
|
+
it "should accept {:type(s) => [T1, ...], :methods => [m, ...]} " do
|
773
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => [:public_test_method]}
|
774
|
+
do_type_pointcut_spec
|
775
|
+
end
|
735
776
|
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
777
|
+
it "should accept {:type(s) => [T1, ...], :methods => m} " do
|
778
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method}
|
779
|
+
do_type_pointcut_spec
|
780
|
+
end
|
740
781
|
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
782
|
+
it "should accept {:type(s) => [T1, ...], :methods => /m/} " do
|
783
|
+
@pointcut_hash = {:type => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
784
|
+
do_type_pointcut_spec
|
785
|
+
end
|
745
786
|
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
787
|
+
it "should accept {:type(s)_and_ancestors => [T1, ...], :methods => /m/} " do
|
788
|
+
@pointcut_hash = {:type_and_ancestors => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
789
|
+
do_type_pointcut_spec
|
790
|
+
end
|
750
791
|
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
792
|
+
it "should accept {:type(s)_and_descendents => [T1, ...], :methods => /m/} " do
|
793
|
+
@pointcut_hash = {:type_and_descendents => [Aquarium::AspectInvocationTestClass], :methods => /test_method/}
|
794
|
+
do_type_pointcut_spec
|
795
|
+
end
|
755
796
|
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
797
|
+
it "should accept {:type(s) => T1, :methods => [m, ...]} " do
|
798
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => [:public_test_method]}
|
799
|
+
do_type_pointcut_spec
|
800
|
+
end
|
760
801
|
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
802
|
+
it "should accept {:type(s) => T1, :methods => m} " do
|
803
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method}
|
804
|
+
do_type_pointcut_spec
|
805
|
+
end
|
765
806
|
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
807
|
+
it "should accept {:type(s) => T1, :methods => /m/} " do
|
808
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
809
|
+
do_type_pointcut_spec
|
810
|
+
end
|
770
811
|
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
812
|
+
it "should accept {:type(s)_and_ancestors => T1, :methods => /m/} " do
|
813
|
+
@pointcut_hash = {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
814
|
+
do_type_pointcut_spec
|
815
|
+
end
|
775
816
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
817
|
+
it "should accept {:type(s)_and_descendents => T1, :methods => /m/} " do
|
818
|
+
@pointcut_hash = {:type_and_descendents => Aquarium::AspectInvocationTestClass, :methods => /test_method/}
|
819
|
+
do_type_pointcut_spec
|
820
|
+
end
|
780
821
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
822
|
+
it "should accept {:type(s) => /T1/, :methods => [m, ...]} " do
|
823
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => [:public_test_method]}
|
824
|
+
do_type_pointcut_spec
|
825
|
+
end
|
785
826
|
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
827
|
+
it "should accept {:type(s) => /T1/, :methods => m} " do
|
828
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => :public_test_method}
|
829
|
+
do_type_pointcut_spec
|
830
|
+
end
|
790
831
|
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
832
|
+
it "should accept {:type(s) => /T1/, :methods => /m/} " do
|
833
|
+
@pointcut_hash = {:type => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
834
|
+
do_type_pointcut_spec
|
835
|
+
end
|
795
836
|
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
837
|
+
it "should accept {:type(s)_and_ancestors => /T1/, :methods => /m/} " do
|
838
|
+
@pointcut_hash = {:type_and_ancestors => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
839
|
+
do_type_pointcut_spec
|
840
|
+
end
|
800
841
|
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
842
|
+
it "should accept {:type(s)_and_descendents => /T1/, :methods => /m/} " do
|
843
|
+
@pointcut_hash = {:type_and_descendents => /Aquarium::AspectInvocationTestClass/, :methods => /test_method/}
|
844
|
+
do_type_pointcut_spec
|
845
|
+
end
|
846
|
+
|
847
|
+
%w[public protected private].each do |protection|
|
848
|
+
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:instance, #{protection}]} " do
|
849
|
+
@protection = protection
|
850
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:instance, protection.intern]}
|
851
|
+
do_type_pointcut_spec
|
852
|
+
end
|
853
|
+
end
|
805
854
|
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
855
|
+
%w[public private].each do |protection|
|
856
|
+
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:class, #{protection}]} " do
|
857
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /class_test_method/, :method_options =>[:class, protection.intern]}
|
858
|
+
@protection = protection
|
859
|
+
@are_class_methods = true
|
860
|
+
do_type_pointcut_spec
|
861
|
+
end
|
862
|
+
end
|
863
|
+
|
864
|
+
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:instance]} defaults to public methods" do
|
865
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:instance]}
|
810
866
|
do_type_pointcut_spec
|
811
867
|
end
|
812
|
-
end
|
813
868
|
|
814
|
-
|
815
|
-
|
816
|
-
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /class_test_method/, :method_options =>[:class, protection.intern]}
|
817
|
-
@protection = protection
|
869
|
+
it "should accept {:type(s) => T1, :methods => /m/, :method_options =>[:class]} defaults to public class methods" do
|
870
|
+
@pointcut_hash = {:type => Aquarium::AspectInvocationTestClass, :methods => /test_method/, :method_options =>[:class]}
|
818
871
|
@are_class_methods = true
|
819
872
|
do_type_pointcut_spec
|
820
873
|
end
|
821
874
|
end
|
822
875
|
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
@are_class_methods = true
|
831
|
-
do_type_pointcut_spec
|
832
|
-
end
|
833
|
-
end
|
834
|
-
|
835
|
-
describe Aspect, ".new (with a :pointcut parameter taking a hash with object specifications)" do
|
836
|
-
before :each do
|
837
|
-
@protection = 'public'
|
838
|
-
@expected_advice_count = 2
|
839
|
-
@object1 = Aquarium::AspectInvocationTestClass.new
|
840
|
-
@object2 = Aquarium::AspectInvocationTestClass.new
|
841
|
-
end
|
876
|
+
describe Aspect, ".new (with a :pointcut parameter taking a hash with object specifications)" do
|
877
|
+
before :each do
|
878
|
+
@protection = 'public'
|
879
|
+
@expected_advice_count = 2
|
880
|
+
@object1 = Aquarium::AspectInvocationTestClass.new
|
881
|
+
@object2 = Aquarium::AspectInvocationTestClass.new
|
882
|
+
end
|
842
883
|
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
884
|
+
def do_object_pointcut_spec
|
885
|
+
aspect = nil
|
886
|
+
advice_count = 0
|
887
|
+
aspect = Aspect.new :before, :pointcut => @pointcut_hash do |jp, obj, *args|
|
888
|
+
advice_count += 1
|
889
|
+
jp.should_not be_nil
|
890
|
+
args.size.should == 4
|
891
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
892
|
+
end
|
893
|
+
@object1.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
894
|
+
@object2.method("#{@protection}_test_method".intern).call :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
895
|
+
advice_count.should == @expected_advice_count
|
896
|
+
aspect.unadvise
|
897
|
+
end
|
857
898
|
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
899
|
+
it "should accept {:objects => [o1, ...], :methods => [m, ...]} " do
|
900
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => [:public_test_method]}
|
901
|
+
do_object_pointcut_spec
|
902
|
+
end
|
862
903
|
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
904
|
+
it "should accept {:objects => [o1, ...], :methods => m} " do
|
905
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => :public_test_method}
|
906
|
+
do_object_pointcut_spec
|
907
|
+
end
|
867
908
|
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
909
|
+
it "should accept {:objects => [o1, ...], :methods => /m/} " do
|
910
|
+
@pointcut_hash = {:objects => [@object1, @object2], :methods => /test_method/}
|
911
|
+
do_object_pointcut_spec
|
912
|
+
end
|
872
913
|
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
914
|
+
it "should accept {:object => o1, :methods => [m, ...]} " do
|
915
|
+
@expected_advice_count = 1
|
916
|
+
@pointcut_hash = {:object => @object1, :methods => [:public_test_method]}
|
917
|
+
do_object_pointcut_spec
|
918
|
+
end
|
878
919
|
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
920
|
+
it "should accept {:objects => o1, :methods => m} " do
|
921
|
+
@expected_advice_count = 1
|
922
|
+
@pointcut_hash = {:objects => @object1, :methods => :public_test_method}
|
923
|
+
do_object_pointcut_spec
|
924
|
+
end
|
884
925
|
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
926
|
+
it "should accept {:objects => o1, :methods => /m/} " do
|
927
|
+
@expected_advice_count = 1
|
928
|
+
@pointcut_hash = {:objects => @object1, :methods => /test_method/}
|
929
|
+
do_object_pointcut_spec
|
930
|
+
end
|
889
931
|
end
|
890
|
-
end
|
891
932
|
|
892
|
-
describe Aspect, ".new (with a :pointcut parameter and a Pointcut object or an array of Pointcuts)" do
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
933
|
+
describe Aspect, ".new (with a :pointcut parameter and a Pointcut object or an array of Pointcuts)" do
|
934
|
+
def do_pointcut_pointcut_spec
|
935
|
+
aspect = nil
|
936
|
+
advice_called = false
|
937
|
+
aspect = Aspect.new :before, :pointcut => @pointcuts do |jp, obj, *args|
|
938
|
+
advice_called = true
|
939
|
+
jp.should_not be_nil
|
940
|
+
args.size.should == 4
|
941
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
942
|
+
end
|
943
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
944
|
+
advice_called.should be_true
|
945
|
+
aspect.unadvise
|
946
|
+
end
|
906
947
|
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
948
|
+
it "should accept a single Pointcut object." do
|
949
|
+
@pointcuts = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
950
|
+
do_pointcut_pointcut_spec
|
951
|
+
end
|
911
952
|
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
953
|
+
it "should accept an array of Pointcut objects." do
|
954
|
+
pointcut1 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
955
|
+
pointcut2 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_class_test_method, :method_options => [:class]
|
956
|
+
@pointcuts = [pointcut1, pointcut2]
|
957
|
+
do_pointcut_pointcut_spec
|
958
|
+
end
|
917
959
|
end
|
918
|
-
end
|
919
960
|
|
920
|
-
describe Aspect, ".new (with a :pointcut parameter and an array of Pointcuts)" do
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
961
|
+
describe Aspect, ".new (with a :pointcut parameter and an array of Pointcuts)" do
|
962
|
+
it "should treat the array as if it is one Pointcut \"or'ed\" together." do
|
963
|
+
advice_called = 0
|
964
|
+
advice = Proc.new {|jp, obj, *args|
|
965
|
+
advice_called += 1
|
966
|
+
jp.should_not be_nil
|
967
|
+
args.size.should == 4
|
968
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
969
|
+
}
|
970
|
+
pointcut1 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_test_method
|
971
|
+
pointcut2 = Pointcut.new :type => [Aquarium::AspectInvocationTestClass], :methods => :public_class_test_method, :method_options => [:class]
|
972
|
+
pointcut12 = pointcut1.or pointcut2
|
973
|
+
aspect1 = Aspect.new :before, :pointcut => [pointcut1, pointcut2], :advice => advice
|
974
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
975
|
+
Aquarium::AspectInvocationTestClass.public_class_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
976
|
+
advice_called.should == 2
|
977
|
+
aspect1.unadvise
|
978
|
+
advice_called = 0
|
979
|
+
aspect2 = Aspect.new :before, :pointcut => pointcut12, :advice => advice
|
980
|
+
Aquarium::AspectInvocationTestClass.new.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
981
|
+
Aquarium::AspectInvocationTestClass.public_class_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
982
|
+
advice_called.should == 2
|
983
|
+
aspect2.unadvise
|
984
|
+
aspect1.join_points_matched.should eql(aspect2.join_points_matched)
|
985
|
+
end
|
944
986
|
end
|
945
|
-
end
|
946
987
|
|
947
|
-
describe Aspect, ".new (with a :type(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters)" do
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
988
|
+
describe Aspect, ".new (with a :type(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters)" do
|
989
|
+
before :each do
|
990
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
991
|
+
@expected_methods = [:public_test_method]
|
992
|
+
end
|
993
|
+
after :each do
|
994
|
+
@aspect1.unadvise
|
995
|
+
@aspect2.unadvise
|
996
|
+
end
|
956
997
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
998
|
+
it "should advise equivalent join points when :type => T and :method => m is used or :pointcut =>{:type => T, :method => m} is used." do
|
999
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1000
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1001
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1002
|
+
end
|
962
1003
|
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
1004
|
+
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
|
1005
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1006
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1007
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1008
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1009
|
+
end
|
969
1010
|
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
1011
|
+
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
|
1012
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1013
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1014
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1015
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1016
|
+
end
|
976
1017
|
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
1018
|
+
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
|
1019
|
+
@aspect1 = Aspect.new :after, :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1020
|
+
join_point = Aquarium::Aspects::JoinPoint.new :type => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1021
|
+
@aspect2 = Aspect.new :after, :pointcut => join_point, &@advice
|
1022
|
+
join_points_should_be_equal 1, @aspect1, @aspect2
|
1023
|
+
end
|
983
1024
|
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
1025
|
+
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
|
1026
|
+
@aspect1 = Aspect.new :after, :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1027
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1028
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1029
|
+
end
|
989
1030
|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
1031
|
+
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
|
1032
|
+
@aspect1 = Aspect.new :after, :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1033
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1034
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1035
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1036
|
+
end
|
996
1037
|
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1038
|
+
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
|
1039
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1040
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_ancestors => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1041
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1042
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1043
|
+
end
|
1003
1044
|
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1045
|
+
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
|
1046
|
+
@aspect1 = Aspect.new :after, :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1047
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1048
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1049
|
+
end
|
1009
1050
|
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1051
|
+
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
|
1052
|
+
@aspect1 = Aspect.new :after, :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method, &@advice
|
1053
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1054
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1055
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1056
|
+
end
|
1016
1057
|
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
end
|
1058
|
+
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
|
1059
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method}, &@advice
|
1060
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type_and_descendents => Aquarium::AspectInvocationTestClass, :method => :public_test_method
|
1061
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1062
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1063
|
+
end
|
1025
1064
|
|
1026
|
-
describe Aspect, ".new (with a :type(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters)" do
|
1027
|
-
class ClassWithAttrib1
|
1028
|
-
def dummy; end
|
1029
|
-
attr_accessor :state
|
1030
1065
|
end
|
1066
|
+
|
1067
|
+
describe Aspect, ".new (with a :type(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters)" do
|
1068
|
+
class ClassWithAttrib1
|
1069
|
+
def dummy; end
|
1070
|
+
attr_accessor :state
|
1071
|
+
end
|
1031
1072
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1073
|
+
before :each do
|
1074
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
1075
|
+
@expected_methods = [:state, :state=]
|
1076
|
+
end
|
1077
|
+
after :each do
|
1078
|
+
@aspect1.unadvise
|
1079
|
+
@aspect2.unadvise
|
1080
|
+
end
|
1040
1081
|
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1082
|
+
it "should not advise any method join points except those corresponding to attribute methods." do
|
1083
|
+
@aspect1 = Aspect.new :after, :type => ClassWithAttrib1, :attribute => :state, &@advice
|
1084
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type => ClassWithAttrib1, :attribute => :state}, &@advice
|
1085
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1086
|
+
end
|
1046
1087
|
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1088
|
+
it "should advise equivalent join points when :type => T and :attribute => a is used or :pointcut =>{:type => T, :attribute => a} is used." do
|
1089
|
+
@aspect1 = Aspect.new :after, :type => ClassWithAttrib1, :attribute => :state, &@advice
|
1090
|
+
@aspect2 = Aspect.new :after, :pointcut => {:type => ClassWithAttrib1, :attribute => :state}, &@advice
|
1091
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1092
|
+
end
|
1052
1093
|
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1094
|
+
it "should advise equivalent join points when :type => T and :attribute => a is used or :pointcut => pointcut is used, where pointcut matches :type => T and :attribute => a." do
|
1095
|
+
@aspect1 = Aspect.new :after, :type => ClassWithAttrib1, :attribute => :state, &@advice
|
1096
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => ClassWithAttrib1, :attribute => :state
|
1097
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1098
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1099
|
+
end
|
1059
1100
|
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1101
|
+
it "should advise equivalent join points when :pointcut =>{:type => T, :attribute => a} is used or :pointcut => pointcut is used, where pointcut matches :type => T and :attribute => a." do
|
1102
|
+
@aspect1 = Aspect.new :after, :pointcut => {:type => ClassWithAttrib1, :attribute => :state}, &@advice
|
1103
|
+
pointcut = Aquarium::Aspects::Pointcut.new :type => ClassWithAttrib1, :attribute => :state
|
1104
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1105
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1106
|
+
end
|
1066
1107
|
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1108
|
+
it "should advise equivalent join points when :type => T and :attribute => a (the attribute's reader and writer) is used or :pointcut => [join_points] is used, where the join_points match :type => T and :method => :a and :method => :a=." do
|
1109
|
+
@aspect1 = Aspect.new :after, :type => ClassWithAttrib1, :attribute => :state, &@advice
|
1110
|
+
join_point1 = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttrib1, :method => :state
|
1111
|
+
join_point2 = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttrib1, :method => :state=
|
1112
|
+
@aspect2 = Aspect.new :after, :pointcut => Pointcut.new(:join_points => [join_point1, join_point2]), &@advice
|
1113
|
+
join_points_should_be_equal 2, @aspect1, @aspect2
|
1114
|
+
end
|
1074
1115
|
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1116
|
+
it "should advise an equivalent join point when :type => T and :method => :a= (the attribute's writer) is used or :pointcut => join_point is used, where join_point matches :type => T and :method => a=." do
|
1117
|
+
@aspect1 = Aspect.new :after, :type => ClassWithAttrib1, :attribute => :state, :attribute_options => [:writer], &@advice
|
1118
|
+
join_point = Aquarium::Aspects::JoinPoint.new :type => ClassWithAttrib1, :method => :state=
|
1119
|
+
@aspect2 = Aspect.new :after, :pointcut => join_point, &@advice
|
1120
|
+
join_points_should_be_equal 1, @aspect1, @aspect2
|
1121
|
+
end
|
1080
1122
|
end
|
1081
|
-
end
|
1082
1123
|
|
1083
|
-
describe Aspect, ".new (with a :object(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters)" do
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1124
|
+
describe Aspect, ".new (with a :object(s) parameter and a :method(s) parameter or one of several equivalent :pointcut parameters)" do
|
1125
|
+
before :each do
|
1126
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
1127
|
+
@expected_methods = [:public_test_method]
|
1128
|
+
end
|
1129
|
+
after :each do
|
1130
|
+
@aspect1.unadvise
|
1131
|
+
@aspect2.unadvise
|
1132
|
+
end
|
1092
1133
|
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1134
|
+
it "should advise equivalent join points when :object => o and :method => m is used or :pointcut =>{:object => o, :method => m} is used." do
|
1135
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1136
|
+
@aspect1 = Aspect.new :after, :object => object, :method => :public_test_method, &@advice
|
1137
|
+
@aspect2 = Aspect.new :after, :pointcut => {:object => object, :method => :public_test_method}, &@advice
|
1138
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1139
|
+
end
|
1099
1140
|
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1141
|
+
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
|
1142
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1143
|
+
@aspect1 = Aspect.new :after, :object => object, :method => :public_test_method, &@advice
|
1144
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => object, :method => :public_test_method
|
1145
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1146
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1147
|
+
end
|
1107
1148
|
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1149
|
+
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
|
1150
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1151
|
+
@aspect1 = Aspect.new :after, :pointcut => {:object => object, :method => :public_test_method}, &@advice
|
1152
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => object, :method => :public_test_method
|
1153
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1154
|
+
aspects_should_be_equal 1, @aspect1, @aspect2
|
1155
|
+
end
|
1114
1156
|
end
|
1115
|
-
end
|
1116
1157
|
|
1117
|
-
describe Aspect, ".new (with a :object(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters)" do
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1158
|
+
describe Aspect, ".new (with a :object(s) parameter and an :attributes(s) parameter or one of several equivalent :pointcut parameters)" do
|
1159
|
+
class ClassWithAttrib2
|
1160
|
+
def initialize *args
|
1161
|
+
@state = args
|
1162
|
+
end
|
1163
|
+
def dummy; end
|
1164
|
+
attr_accessor :state
|
1121
1165
|
end
|
1122
|
-
def dummy; end
|
1123
|
-
attr_accessor :state
|
1124
|
-
end
|
1125
1166
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1167
|
+
before :each do
|
1168
|
+
@advice = proc {|jp, obj, *args| "advice"}
|
1169
|
+
@object = ClassWithAttrib2.new
|
1170
|
+
@expected_methods = [:state, :state=]
|
1171
|
+
end
|
1172
|
+
after :each do
|
1173
|
+
@aspect1.unadvise
|
1174
|
+
@aspect2.unadvise
|
1175
|
+
end
|
1135
1176
|
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1177
|
+
it "should not advise any method join points except those corresponding to attribute methods." do
|
1178
|
+
@aspect1 = Aspect.new :after, :object => @object, :attribute => :state, &@advice
|
1179
|
+
@aspect2 = Aspect.new :after, :pointcut => {:object => @object, :attribute => :state}, &@advice
|
1180
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1181
|
+
end
|
1141
1182
|
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1183
|
+
it "should advise equivalent join points when :type => T and :attribute => a is used or :pointcut =>{:type => T, :attribute => a} is used." do
|
1184
|
+
@aspect1 = Aspect.new :after, :object => @object, :attribute => :state, &@advice
|
1185
|
+
@aspect2 = Aspect.new :after, :pointcut => {:object => @object, :attribute => :state}, &@advice
|
1186
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1187
|
+
end
|
1147
1188
|
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1189
|
+
it "should advise equivalent join points when :type => T and :attribute => a is used or :pointcut => pointcut is used, where pointcut matches :type => T and :attribute => a." do
|
1190
|
+
@aspect1 = Aspect.new :after, :object => @object, :attribute => :state, &@advice
|
1191
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => @object, :attribute => :state
|
1192
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1193
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1194
|
+
end
|
1154
1195
|
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1196
|
+
it "should advise equivalent join points when :pointcut =>{:type => T, :attribute => a} is used or :pointcut => pointcut is used, where pointcut matches :type => T and :attribute => a." do
|
1197
|
+
@aspect1 = Aspect.new :after, :pointcut => {:object => @object, :attribute => :state}, &@advice
|
1198
|
+
pointcut = Aquarium::Aspects::Pointcut.new :object => @object, :attribute => :state
|
1199
|
+
@aspect2 = Aspect.new :after, :pointcut => pointcut, &@advice
|
1200
|
+
aspects_should_be_equal 2, @aspect1, @aspect2
|
1201
|
+
end
|
1161
1202
|
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1203
|
+
it "should advise equivalent join points when :type => T and :attribute => a (the attribute's reader and writer) is used or :pointcut => [join_points] is used, where the join_points match :type => T and :method => :a and :method => :a=." do
|
1204
|
+
@aspect1 = Aspect.new :after, :object => @object, :attribute => :state, &@advice
|
1205
|
+
join_point1 = Aquarium::Aspects::JoinPoint.new :object => @object, :method => :state
|
1206
|
+
join_point2 = Aquarium::Aspects::JoinPoint.new :object => @object, :method => :state=
|
1207
|
+
@aspect2 = Aspect.new :after, :pointcut => Pointcut.new(:join_points => [join_point1, join_point2]), &@advice
|
1208
|
+
join_points_should_be_equal 2, @aspect1, @aspect2
|
1209
|
+
end
|
1169
1210
|
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1211
|
+
it "should advise an equivalent join point when :type => T and :method => :a= (the attribute's writer) is used or :pointcut => join_point is used, where join_point matches :type => T and :method => a=." do
|
1212
|
+
@aspect1 = Aspect.new :after, :object => @object, :attribute => :state, :attribute_options => [:writer], &@advice
|
1213
|
+
join_point = Aquarium::Aspects::JoinPoint.new :object => @object, :method => :state=
|
1214
|
+
@aspect2 = Aspect.new :after, :pointcut => join_point, &@advice
|
1215
|
+
join_points_should_be_equal 1, @aspect1, @aspect2
|
1216
|
+
end
|
1175
1217
|
end
|
1176
|
-
end
|
1177
1218
|
|
1178
|
-
describe Aspect, ".new (block for advice)" do
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1219
|
+
describe Aspect, ".new (block for advice)" do
|
1220
|
+
it "should accept a block as the advice to use." do
|
1221
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1222
|
+
advice_called = false
|
1223
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method do |jp, obj, *args|
|
1224
|
+
advice_called = true
|
1225
|
+
jp.should_not be_nil
|
1226
|
+
args.size.should == 4
|
1227
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1228
|
+
end
|
1229
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1230
|
+
advice_called.should be_true
|
1231
|
+
aspect.unadvise
|
1232
|
+
end
|
1192
1233
|
|
1193
|
-
|
1194
|
-
object = Aquarium::AspectInvocationTestClass.new
|
1195
|
-
advice_called = false
|
1196
|
-
advice = Proc.new {|jp, obj, *args|
|
1197
|
-
advice_called = true
|
1198
|
-
jp.should_not be_nil
|
1199
|
-
args.size.should == 4
|
1200
|
-
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1201
|
-
}
|
1202
|
-
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice
|
1203
|
-
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1204
|
-
advice_called.should be_true
|
1205
|
-
aspect.unadvise
|
1206
|
-
end
|
1207
|
-
|
1208
|
-
Aspect::CANONICAL_OPTIONS["advice"].each do |key|
|
1209
|
-
it "should accept :#{key} => proc as a synonym for :advice." do
|
1234
|
+
it "should accept an :advice => Proc parameter indicating the advice to use." do
|
1210
1235
|
object = Aquarium::AspectInvocationTestClass.new
|
1211
1236
|
advice_called = false
|
1212
1237
|
advice = Proc.new {|jp, obj, *args|
|
@@ -1215,612 +1240,653 @@ describe Aspect, ".new (block for advice)" do
|
|
1215
1240
|
args.size.should == 4
|
1216
1241
|
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1217
1242
|
}
|
1218
|
-
aspect = Aspect.new :before, :object => object, :methods => :public_test_method,
|
1243
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice
|
1219
1244
|
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1220
1245
|
advice_called.should be_true
|
1221
1246
|
aspect.unadvise
|
1222
1247
|
end
|
1223
|
-
end
|
1224
1248
|
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
end
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1249
|
+
Aspect::CANONICAL_OPTIONS["advice"].each do |key|
|
1250
|
+
it "should accept :#{key} => proc as a synonym for :advice." do
|
1251
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1252
|
+
advice_called = false
|
1253
|
+
advice = Proc.new {|jp, obj, *args|
|
1254
|
+
advice_called = true
|
1255
|
+
jp.should_not be_nil
|
1256
|
+
args.size.should == 4
|
1257
|
+
args.should == [:a1, :a2, :a3, {:h1 => 'h1', :h2 => 'h2'}]
|
1258
|
+
}
|
1259
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, key.intern => advice
|
1260
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1261
|
+
advice_called.should be_true
|
1262
|
+
aspect.unadvise
|
1263
|
+
end
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
it "should allow only one :advice object to be specified (including synonyms)." do
|
1267
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1268
|
+
advice_called = false
|
1269
|
+
advice1 = Proc.new {|jp, obj, *args| fail "advice1"}
|
1270
|
+
advice2 = Proc.new {|jp, obj, *args| fail "advice2"}
|
1271
|
+
lambda {Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice1, :invoke => advice2}.should raise_error(Aquarium::Utils::InvalidOptions)
|
1272
|
+
end
|
1245
1273
|
|
1246
|
-
|
1274
|
+
it "should allow ignore an :advice option if a block is given." do
|
1275
|
+
object = Aquarium::AspectInvocationTestClass.new
|
1276
|
+
advice_called = false
|
1277
|
+
advice1 = Proc.new {|jp, obj, *args| fail "advice1"}
|
1278
|
+
advice2 = Proc.new {|jp, obj, *args| fail "advice2"}
|
1279
|
+
aspect = Aspect.new :before, :object => object, :methods => :public_test_method, :advice => advice1 do |jp, obj, *args|
|
1280
|
+
advice_called = true
|
1281
|
+
end
|
1282
|
+
object.public_test_method :a1, :a2, :a3, :h1 => 'h1', :h2 => 'h2'
|
1283
|
+
advice_called.should be_true
|
1284
|
+
aspect.unadvise
|
1285
|
+
end
|
1247
1286
|
|
1248
|
-
describe Aspect, ".new (advice block or proc parameter list)" do
|
1249
|
-
it "should raise unless an advice block or :advice => advice parameter is specified." do
|
1250
|
-
lambda {Aspect.new(:after, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method)}.should raise_error(Aquarium::Utils::InvalidOptions)
|
1251
1287
|
end
|
1252
1288
|
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1289
|
+
describe Aspect, ".new (advice block or proc parameter list)" do
|
1290
|
+
it "should raise unless an advice block or :advice => advice parameter is specified." do
|
1291
|
+
lambda {Aspect.new(:after, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method)}.should raise_error(Aquarium::Utils::InvalidOptions)
|
1292
|
+
end
|
1256
1293
|
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1294
|
+
it "should raise if obsolete |jp, *args| list is used." do
|
1295
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method do |jp, *args|; end }.should raise_error(Aquarium::Utils::InvalidOptions)
|
1296
|
+
end
|
1260
1297
|
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1298
|
+
it "should accept an argument list matching |jp, object, *args|." do
|
1299
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp, object, *args|; end }.should_not raise_error(Exception)
|
1300
|
+
end
|
1264
1301
|
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1302
|
+
it "should accept an argument list matching |jp, object|." do
|
1303
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp, object|; end }.should_not raise_error(Exception)
|
1304
|
+
end
|
1268
1305
|
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1306
|
+
it "should accept an argument list matching |jp|." do
|
1307
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do |jp|; end }.should_not raise_error(Exception)
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
it "should accept an argument list matching ||." do
|
1311
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do ||; end }.should_not raise_error(Exception)
|
1312
|
+
end
|
1272
1313
|
|
1273
|
-
|
1274
|
-
|
1314
|
+
it "should accept no argument list." do
|
1315
|
+
lambda { Aspect.new :before, :type => Aquarium::AspectInvocationTestClass, :methods => :public_test_method, :noop => true do; end }.should_not raise_error(Exception)
|
1316
|
+
end
|
1275
1317
|
end
|
1276
|
-
end
|
1277
1318
|
|
1278
1319
|
|
1279
|
-
class ExcludeBase
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
end
|
1290
|
-
class DontExclude1 < ExcludeBase; end
|
1291
|
-
class DontExclude2 < ExcludeBase; end
|
1292
|
-
class Exclude1 < ExcludeBase; end
|
1293
|
-
class Exclude2 < ExcludeBase; end
|
1294
|
-
|
1295
|
-
class Exclude1b < Exclude1
|
1296
|
-
|
1297
|
-
|
1298
|
-
end
|
1299
|
-
class Exclude1c < Exclude1
|
1300
|
-
|
1301
|
-
|
1302
|
-
end
|
1303
|
-
|
1304
|
-
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
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
advice_called = false
|
1310
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), exclude_type_sym => excluded_types, :methods => :doit do |jp, obj, *args|
|
1311
|
-
advice_called = true
|
1312
|
-
excluded_types.should_not include(jp.target_type)
|
1313
|
-
end
|
1314
|
-
included_types.each do |type|
|
1315
|
-
advice_called = false
|
1316
|
-
type.new(1).doit
|
1317
|
-
advice_called.should be_true
|
1320
|
+
class ExcludeBase
|
1321
|
+
def doit; end
|
1322
|
+
def initialize arg; @value = arg; end
|
1323
|
+
attr_accessor :value
|
1324
|
+
def inspect; "(#{self.class}: #{@value})"; end
|
1325
|
+
def eql? other
|
1326
|
+
return false unless other.kind_of?(self.class)
|
1327
|
+
@value == other.value
|
1328
|
+
end
|
1329
|
+
alias_method :==, :eql?
|
1330
|
+
end
|
1331
|
+
class DontExclude1 < ExcludeBase; end
|
1332
|
+
class DontExclude2 < ExcludeBase; end
|
1333
|
+
class Exclude1 < ExcludeBase; end
|
1334
|
+
class Exclude2 < ExcludeBase; end
|
1335
|
+
|
1336
|
+
class Exclude1b < Exclude1
|
1337
|
+
def initialize arg; super(arg); end
|
1338
|
+
def doit2; end
|
1339
|
+
end
|
1340
|
+
class Exclude1c < Exclude1
|
1341
|
+
def initialize arg; super(arg); end
|
1342
|
+
def doit3; end
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
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
|
1346
|
+
before :all do
|
1347
|
+
@included_types = [DontExclude1, DontExclude2]
|
1348
|
+
@excluded_types = [Exclude1, Exclude2]
|
1349
|
+
@all_types = @included_types + @excluded_types
|
1318
1350
|
end
|
1319
|
-
|
1351
|
+
|
1352
|
+
def do_exclude_types exclude_type_sym
|
1353
|
+
aspect = nil
|
1320
1354
|
advice_called = false
|
1321
|
-
|
1322
|
-
|
1355
|
+
aspect = Aspect.new :before, :types => @all_types, exclude_type_sym => @excluded_types, :methods => :doit do |jp, obj, *args|
|
1356
|
+
advice_called = true
|
1357
|
+
@excluded_types.should_not include(jp.target_type)
|
1358
|
+
end
|
1359
|
+
@included_types.each do |type|
|
1360
|
+
advice_called = false
|
1361
|
+
type.new(1).doit
|
1362
|
+
advice_called.should be_true
|
1363
|
+
end
|
1364
|
+
@excluded_types.each do |type|
|
1365
|
+
advice_called = false
|
1366
|
+
type.new(1).doit
|
1367
|
+
advice_called.should_not be_true
|
1368
|
+
end
|
1369
|
+
aspect.unadvise
|
1323
1370
|
end
|
1324
|
-
aspect.unadvise
|
1325
|
-
end
|
1326
1371
|
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1372
|
+
it "should accept :type(s) => [T1, ...], :exclude_types => [T2, ...] and exclude join points in the excluded types" do
|
1373
|
+
do_exclude_types :exclude_types
|
1374
|
+
end
|
1330
1375
|
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1376
|
+
Aspect::CANONICAL_OPTIONS["exclude_types"].each do |key|
|
1377
|
+
it "should accept :#{key} as a synonym for :exclude_types." do
|
1378
|
+
lambda { Aspect.new :before, :types => @all_types, key.intern => @excluded_types, :methods => :doit, :noop => true do; end }.should_not raise_error
|
1379
|
+
end
|
1334
1380
|
end
|
1335
|
-
end
|
1336
1381
|
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1382
|
+
it "should accept :type(s) => [T1, ...], :exclude_types_and_ancestors => [T2, ...] and exclude join points in the excluded types" do
|
1383
|
+
do_exclude_types :exclude_types_and_ancestors
|
1384
|
+
end
|
1340
1385
|
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1386
|
+
Aspect::CANONICAL_OPTIONS["exclude_types_and_ancestors"].each do |key|
|
1387
|
+
it "should accept :#{key} as a synonym for :exclude_types_and_ancestors." do
|
1388
|
+
lambda { Aspect.new :before, :types => @all_types, key.intern => @excluded_types, :methods => :doit, :noop => true do; end }.should_not raise_error
|
1389
|
+
end
|
1344
1390
|
end
|
1345
|
-
end
|
1346
1391
|
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1392
|
+
it "should accept :type(s) => [T1, ...], :exclude_types_and_descendents => [T2, ...] and exclude join points in the excluded types" do
|
1393
|
+
do_exclude_types :exclude_types_and_descendents
|
1394
|
+
end
|
1350
1395
|
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1396
|
+
Aspect::CANONICAL_OPTIONS["exclude_types_and_descendents"].each do |key|
|
1397
|
+
it "should accept :#{key} as a synonym for :exclude_types_and_descendents." do
|
1398
|
+
lambda { Aspect.new :before, :types => @all_types, key.intern => @excluded_types, :methods => :doit, :noop => true do; end }.should_not raise_error
|
1399
|
+
end
|
1354
1400
|
end
|
1355
|
-
end
|
1356
1401
|
|
1357
|
-
end
|
1402
|
+
end
|
1358
1403
|
|
1359
1404
|
|
1360
|
-
describe Aspect, ".new (with a :object(s) parameter and an :exclude_object(s) parameter)" do
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
advice_called = false
|
1370
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_object_sym => excluded_objects, :methods => :doit do |jp, obj, *args|
|
1371
|
-
advice_called = true
|
1372
|
-
excluded_objects.should_not include(obj)
|
1373
|
-
end
|
1374
|
-
included_objects.each do |object|
|
1375
|
-
advice_called = false
|
1376
|
-
object.doit
|
1377
|
-
advice_called.should be_true
|
1405
|
+
describe Aspect, ".new (with a :object(s) parameter and an :exclude_object(s) parameter)" do
|
1406
|
+
before :all do
|
1407
|
+
dontExclude1 = DontExclude1.new(1)
|
1408
|
+
dontExclude2 = DontExclude1.new(2)
|
1409
|
+
exclude1 = DontExclude1.new(3)
|
1410
|
+
exclude2 = DontExclude1.new(4)
|
1411
|
+
@included_objects = [dontExclude1, dontExclude2]
|
1412
|
+
@excluded_objects = [exclude1, exclude2]
|
1413
|
+
@all_objects = @included_objects + @excluded_objects
|
1378
1414
|
end
|
1379
|
-
|
1415
|
+
|
1416
|
+
it "should accept :object(s) => [o1, ...], :exclude_object(s) => [o2, ...] and exclude join points in the excluded objects" do
|
1417
|
+
aspect = nil
|
1380
1418
|
advice_called = false
|
1381
|
-
|
1382
|
-
|
1419
|
+
aspect = Aspect.new :before, :objects => @all_objects, :exclude_objects => @excluded_objects, :methods => :doit do |jp, obj, *args|
|
1420
|
+
advice_called = true
|
1421
|
+
@excluded_objects.should_not include(obj)
|
1422
|
+
end
|
1423
|
+
@included_objects.each do |object|
|
1424
|
+
advice_called = false
|
1425
|
+
object.doit
|
1426
|
+
advice_called.should be_true
|
1427
|
+
end
|
1428
|
+
@excluded_objects.each do |object|
|
1429
|
+
advice_called = false
|
1430
|
+
object.doit
|
1431
|
+
advice_called.should_not be_true
|
1432
|
+
end
|
1433
|
+
aspect.unadvise
|
1383
1434
|
end
|
1384
|
-
aspect.unadvise
|
1385
|
-
end
|
1386
|
-
|
1387
|
-
it "should accept :object(s) => [o1, ...], :exclude_object(s) => [o2, ...] and exclude join points in the excluded objects" do
|
1388
|
-
do_exclude_objects :exclude_objects
|
1389
|
-
end
|
1390
1435
|
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1436
|
+
Aspect::CANONICAL_OPTIONS["exclude_objects"].each do |key|
|
1437
|
+
it "should accept :#{key} as a synonym for :exclude_objects." do
|
1438
|
+
lambda { Aspect.new :before, :objects => @all_objects, key.intern => @excluded_objects, :methods => :doit, :noop => true do; end }.should_not raise_error
|
1439
|
+
end
|
1394
1440
|
end
|
1395
1441
|
end
|
1396
|
-
end
|
1397
1442
|
|
1398
1443
|
|
1399
|
-
describe Aspect, ".new (with
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
advice_called = false
|
1412
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_join_points_sym => excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1413
|
-
advice_called = true
|
1414
|
-
excluded_objects.should_not include(obj)
|
1415
|
-
end
|
1416
|
-
|
1417
|
-
included_objects.each do |object|
|
1418
|
-
advice_called = false
|
1419
|
-
object.doit
|
1420
|
-
advice_called.should be_true
|
1444
|
+
describe Aspect, ".new (with an :object(s) and an :exclude_join_point(s) parameter)" do
|
1445
|
+
before :all do
|
1446
|
+
dontExclude1 = DontExclude1.new(1)
|
1447
|
+
dontExclude2 = DontExclude1.new(2)
|
1448
|
+
exclude1 = DontExclude1.new(3)
|
1449
|
+
exclude2 = DontExclude1.new(4)
|
1450
|
+
@included_objects = [dontExclude1, dontExclude2]
|
1451
|
+
@excluded_objects = [exclude1, exclude2]
|
1452
|
+
@all_objects = @included_objects + @excluded_objects
|
1453
|
+
excluded_join_point1 = JoinPoint.new :object => exclude1, :method => :doit
|
1454
|
+
excluded_join_point2 = JoinPoint.new :object => exclude2, :method => :doit
|
1455
|
+
@excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1421
1456
|
end
|
1422
|
-
|
1457
|
+
|
1458
|
+
it "should accept :type(s) => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1459
|
+
aspect = nil
|
1423
1460
|
advice_called = false
|
1424
|
-
|
1425
|
-
|
1461
|
+
aspect = Aspect.new :before, :objects => @all_objects, :exclude_join_points => @excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1462
|
+
advice_called = true
|
1463
|
+
@excluded_objects.should_not include(obj)
|
1464
|
+
end
|
1465
|
+
|
1466
|
+
@included_objects.each do |object|
|
1467
|
+
advice_called = false
|
1468
|
+
object.doit
|
1469
|
+
advice_called.should be_true
|
1470
|
+
end
|
1471
|
+
@excluded_objects.each do |object|
|
1472
|
+
advice_called = false
|
1473
|
+
object.doit
|
1474
|
+
advice_called.should_not be_true
|
1475
|
+
end
|
1476
|
+
aspect.unadvise
|
1426
1477
|
end
|
1427
|
-
aspect.unadvise
|
1428
|
-
end
|
1429
1478
|
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1479
|
+
Aspect::CANONICAL_OPTIONS["exclude_join_points"].each do |key|
|
1480
|
+
it "should accept :#{key} as a synonym for :exclude_join_points." do
|
1481
|
+
lambda { Aspect.new :before, :objects => @all_objects, key.intern => @excluded_join_points, :methods => :doit, :noop => true do; end }.should_not raise_error
|
1482
|
+
end
|
1483
|
+
end
|
1484
|
+
end
|
1485
|
+
|
1486
|
+
describe Aspect, ".new (with a :type(s) parameter and an :exclude_join_point(s) parameter)" do
|
1487
|
+
it "should accept :type(s) => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1488
|
+
included_types = [DontExclude1, DontExclude2]
|
1489
|
+
excluded_types = [Exclude1, Exclude2]
|
1490
|
+
excluded_join_point1 = JoinPoint.new :type => Exclude1, :method => :doit
|
1491
|
+
excluded_join_point2 = JoinPoint.new :type => Exclude2, :method => :doit
|
1492
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1493
|
+
aspect = nil
|
1494
|
+
advice_called = false
|
1495
|
+
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_join_points => excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1496
|
+
advice_called = true
|
1497
|
+
excluded_types.should_not include(jp.target_type)
|
1498
|
+
end
|
1499
|
+
|
1500
|
+
included_types.each do |type|
|
1501
|
+
advice_called = false
|
1502
|
+
type.new(1).doit
|
1503
|
+
advice_called.should be_true
|
1504
|
+
end
|
1505
|
+
excluded_types.each do |type|
|
1506
|
+
advice_called = false
|
1507
|
+
type.new(1).doit
|
1508
|
+
advice_called.should_not be_true
|
1509
|
+
end
|
1510
|
+
aspect.unadvise
|
1433
1511
|
end
|
1434
1512
|
end
|
1435
1513
|
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
excluded_join_point1 = JoinPoint.new :type => Exclude1, :method => :doit
|
1444
|
-
excluded_join_point2 = JoinPoint.new :type => Exclude2, :method => :doit
|
1445
|
-
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1446
|
-
aspect = nil
|
1447
|
-
advice_called = false
|
1448
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_join_points => excluded_join_points, :methods => :doit do |jp, obj, *args|
|
1449
|
-
advice_called = true
|
1450
|
-
excluded_types.should_not include(jp.target_type)
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
included_types.each do |type|
|
1514
|
+
describe Aspect, ".new (with a :type(s)_and_ancestors parameter and an :exclude_join_point(s) parameter)" do
|
1515
|
+
it "should accept :type(s)_and_ancestors => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1516
|
+
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1517
|
+
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1518
|
+
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1519
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1520
|
+
aspect = nil
|
1454
1521
|
advice_called = false
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
excluded_types.each do |type|
|
1522
|
+
aspect = Aspect.new :before, :types_and_ancestors => included_types, :methods => :doit,
|
1523
|
+
:exclude_join_points => excluded_join_points, :ignore_no_matching_join_points => true do |jp, obj, *args|; advice_called = true; end
|
1524
|
+
|
1459
1525
|
advice_called = false
|
1460
|
-
|
1461
|
-
advice_called.
|
1526
|
+
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1527
|
+
advice_called.should be_false
|
1528
|
+
advice_called = false
|
1529
|
+
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1530
|
+
advice_called.should be_false
|
1531
|
+
aspect.unadvise
|
1462
1532
|
end
|
1463
|
-
aspect.unadvise
|
1464
|
-
end
|
1465
|
-
|
1466
|
-
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
|
1467
|
-
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1468
|
-
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1469
|
-
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1470
|
-
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1471
|
-
aspect = nil
|
1472
|
-
advice_called = false
|
1473
|
-
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
|
1474
|
-
|
1475
|
-
advice_called = false
|
1476
|
-
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1477
|
-
advice_called.should be_false
|
1478
|
-
advice_called = false
|
1479
|
-
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1480
|
-
advice_called.should be_false
|
1481
|
-
aspect.unadvise
|
1482
|
-
end
|
1483
|
-
|
1484
|
-
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
|
1485
|
-
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1486
|
-
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1487
|
-
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1488
|
-
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1489
|
-
aspect = nil
|
1490
|
-
advice_called = false
|
1491
|
-
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
|
1492
|
-
|
1493
|
-
advice_called = false
|
1494
|
-
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1495
|
-
advice_called.should be_false
|
1496
|
-
advice_called = false
|
1497
|
-
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1498
|
-
advice_called.should be_false
|
1499
|
-
aspect.unadvise
|
1500
1533
|
end
|
1534
|
+
|
1535
|
+
describe Aspect, ".new (with a :type(s)_and_descendents parameter and an :exclude_join_point(s) parameter)" do
|
1536
|
+
it "should accept :type(s)_and_descendents => [T1, ...], :exclude_join_point(s) => [jps], where [jps] are the list of join points for the types and methods to exclude" do
|
1537
|
+
included_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1538
|
+
excluded_join_point1 = JoinPoint.new :type => ClassWithPublicInstanceMethod, :method => :public_instance_test_method
|
1539
|
+
excluded_join_point2 = JoinPoint.new :type => ModuleWithPublicInstanceMethod, :method => :public_instance_module_test_method
|
1540
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1541
|
+
aspect = nil
|
1542
|
+
advice_called = false
|
1543
|
+
aspect = Aspect.new :before, :types_and_descendents => included_types, :methods => :doit,
|
1544
|
+
:exclude_join_points => excluded_join_points, :ignore_no_matching_join_points => true do |jp, obj, *args|; advice_called = true; end
|
1501
1545
|
|
1502
|
-
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
|
1503
|
-
included_types = [DontExclude1, DontExclude2]
|
1504
|
-
excluded_types = [Exclude1, Exclude2]
|
1505
|
-
excluded_join_point1 = JoinPoint.new :type => Exclude1, :method => :doit
|
1506
|
-
excluded_join_point2 = JoinPoint.new :type => Exclude2, :method => :doit
|
1507
|
-
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1508
|
-
pointcut1 = Pointcut.new :types => included_types, :method => :doit
|
1509
|
-
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1510
|
-
aspect = nil
|
1511
|
-
advice_called = false
|
1512
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_join_points => excluded_join_points do |jp, obj, *args|
|
1513
|
-
advice_called = true
|
1514
|
-
excluded_types.should_not include(jp.target_type)
|
1515
|
-
end
|
1516
|
-
included_types.each do |type|
|
1517
1546
|
advice_called = false
|
1518
|
-
|
1519
|
-
advice_called.should
|
1547
|
+
ClassWithPublicInstanceMethod.new.public_instance_test_method
|
1548
|
+
advice_called.should be_false
|
1549
|
+
advice_called = false
|
1550
|
+
ClassIncludingModuleWithPublicInstanceMethod.new.public_instance_module_test_method
|
1551
|
+
advice_called.should be_false
|
1552
|
+
aspect.unadvise
|
1520
1553
|
end
|
1521
|
-
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
describe Aspect, ".new (with a :pointcut(s) parameter and an :exclude_join_point(s) parameter)" do
|
1557
|
+
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
|
1558
|
+
included_types = [DontExclude1, DontExclude2]
|
1559
|
+
excluded_types = [Exclude1, Exclude2]
|
1560
|
+
excluded_join_point1 = JoinPoint.new :type => Exclude1, :method => :doit
|
1561
|
+
excluded_join_point2 = JoinPoint.new :type => Exclude2, :method => :doit
|
1562
|
+
excluded_join_points = [excluded_join_point1, excluded_join_point2]
|
1563
|
+
pointcut1 = Pointcut.new :types => included_types, :method => :doit
|
1564
|
+
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1565
|
+
aspect = nil
|
1522
1566
|
advice_called = false
|
1523
|
-
|
1524
|
-
|
1567
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_join_points => excluded_join_points do |jp, obj, *args|
|
1568
|
+
advice_called = true
|
1569
|
+
excluded_types.should_not include(jp.target_type)
|
1570
|
+
end
|
1571
|
+
included_types.each do |type|
|
1572
|
+
advice_called = false
|
1573
|
+
type.new(1).doit
|
1574
|
+
advice_called.should be_true
|
1575
|
+
end
|
1576
|
+
excluded_types.each do |type|
|
1577
|
+
advice_called = false
|
1578
|
+
type.new(1).doit
|
1579
|
+
advice_called.should_not be_true
|
1580
|
+
end
|
1581
|
+
aspect.unadvise
|
1525
1582
|
end
|
1526
|
-
aspect.unadvise
|
1527
1583
|
end
|
1528
|
-
end
|
1529
1584
|
|
1530
|
-
describe Aspect, ".new (with
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
advice_called = false
|
1543
|
-
aspect = Aspect.new :before, :objects => (included_objects + excluded_objects), exclude_pointcuts_sym => excluded_pointcuts, :methods => :doit do |jp, obj, *args|
|
1544
|
-
advice_called = true
|
1545
|
-
excluded_objects.should_not include(obj)
|
1546
|
-
end
|
1547
|
-
|
1548
|
-
included_objects.each do |object|
|
1549
|
-
advice_called = false
|
1550
|
-
object.doit
|
1551
|
-
advice_called.should be_true
|
1585
|
+
describe Aspect, ".new (with an :object(s) and an :exclude_pointcut(s) parameter)" do
|
1586
|
+
before :all do
|
1587
|
+
dontExclude1 = DontExclude1.new(1)
|
1588
|
+
dontExclude2 = DontExclude1.new(2)
|
1589
|
+
exclude1 = DontExclude1.new(3)
|
1590
|
+
exclude2 = DontExclude1.new(4)
|
1591
|
+
@included_objects = [dontExclude1, dontExclude2]
|
1592
|
+
@excluded_objects = [exclude1, exclude2]
|
1593
|
+
@all_objects = @included_objects + @excluded_objects
|
1594
|
+
excluded_pointcut1 = Pointcut.new :object => exclude1, :method => :doit
|
1595
|
+
excluded_pointcut2 = Pointcut.new :object => exclude2, :method => :doit
|
1596
|
+
@excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1552
1597
|
end
|
1553
|
-
|
1598
|
+
|
1599
|
+
it "should accept :object(s) => [o1, ...], :exclude_pointcut(s) => [pcs], where [pcs] are the list of pointcuts for the objects and methods to exclude" do
|
1600
|
+
aspect = nil
|
1554
1601
|
advice_called = false
|
1555
|
-
|
1556
|
-
|
1602
|
+
aspect = Aspect.new :before, :objects => @all_objects, :methods => :doit, :exclude_pointcuts => @excluded_pointcuts, :ignore_no_matching_join_points => true do |jp, obj, *args|
|
1603
|
+
advice_called = true
|
1604
|
+
@excluded_objects.should_not include(obj)
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
@included_objects.each do |object|
|
1608
|
+
advice_called = false
|
1609
|
+
object.doit
|
1610
|
+
advice_called.should be_true
|
1611
|
+
end
|
1612
|
+
@excluded_objects.each do |object|
|
1613
|
+
advice_called = false
|
1614
|
+
object.doit
|
1615
|
+
advice_called.should_not be_true
|
1616
|
+
end
|
1617
|
+
aspect.unadvise
|
1557
1618
|
end
|
1558
|
-
aspect.unadvise
|
1559
|
-
end
|
1560
1619
|
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1620
|
+
Aspect::CANONICAL_OPTIONS["exclude_pointcuts"].each do |key|
|
1621
|
+
it "should accept :#{key} as a synonym for :exclude_pointcuts." do
|
1622
|
+
lambda {aspect = Aspect.new :before, :objects => @all_objects, :exclude_pointcuts => @excluded_pointcuts, :methods => :doit, :noop => true do; end}.should_not raise_error
|
1623
|
+
end
|
1564
1624
|
end
|
1565
1625
|
end
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
excluded_pointcut2 = Pointcut.new :type => Exclude2, :method => :doit
|
1576
|
-
excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1577
|
-
aspect = nil
|
1578
|
-
advice_called = false
|
1579
|
-
aspect = Aspect.new :before, :types => (included_types + excluded_types), :exclude_pointcuts => excluded_pointcuts, :methods => :doit do |jp, obj, *args|
|
1580
|
-
advice_called = true
|
1581
|
-
excluded_types.should_not include(jp.target_type)
|
1582
|
-
end
|
1583
|
-
|
1584
|
-
included_types.each do |type|
|
1585
|
-
advice_called = false
|
1586
|
-
type.new(1).doit
|
1587
|
-
advice_called.should be_true
|
1626
|
+
|
1627
|
+
describe Aspect, ".new (with a :type(s) and an :exclude_pointcut(s) parameter)" do
|
1628
|
+
before :all do
|
1629
|
+
@included_types = [DontExclude1, DontExclude2]
|
1630
|
+
@excluded_types = [Exclude1, Exclude2]
|
1631
|
+
@all_types = @included_types + @excluded_types
|
1632
|
+
excluded_pointcut1 = Pointcut.new :type => Exclude1, :method => :doit
|
1633
|
+
excluded_pointcut2 = Pointcut.new :type => Exclude2, :method => :doit
|
1634
|
+
@excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1588
1635
|
end
|
1589
|
-
|
1636
|
+
|
1637
|
+
it "should accept :type(s) => [T1, ...], :exclude_pointcut(s) => [pcs], where [pcs] are the list of pointcuts for the types and methods to exclude" do
|
1638
|
+
aspect = nil
|
1590
1639
|
advice_called = false
|
1591
|
-
|
1592
|
-
|
1640
|
+
aspect = Aspect.new :before, :types => @all_types, :exclude_pointcuts => @excluded_pointcuts, :methods => :doit do |jp, obj, *args|
|
1641
|
+
advice_called = true
|
1642
|
+
@excluded_types.should_not include(jp.target_type)
|
1643
|
+
end
|
1644
|
+
|
1645
|
+
@included_types.each do |type|
|
1646
|
+
advice_called = false
|
1647
|
+
type.new(1).doit
|
1648
|
+
advice_called.should be_true
|
1649
|
+
end
|
1650
|
+
@excluded_types.each do |type|
|
1651
|
+
advice_called = false
|
1652
|
+
type.new(1).doit
|
1653
|
+
advice_called.should_not be_true
|
1654
|
+
end
|
1655
|
+
aspect.unadvise
|
1593
1656
|
end
|
1594
|
-
aspect.unadvise
|
1595
1657
|
end
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
advice_called = true
|
1609
|
-
excluded_types.should_not include(jp.target_type)
|
1610
|
-
end
|
1611
|
-
included_types.each do |type|
|
1612
|
-
advice_called = false
|
1613
|
-
type.new(1).doit
|
1614
|
-
advice_called.should be_true
|
1658
|
+
|
1659
|
+
describe Aspect, ".new (with a :pointcut(s) and an :exclude_pointcut(s) parameter)" do
|
1660
|
+
before :all do
|
1661
|
+
@included_types = [DontExclude1, DontExclude2]
|
1662
|
+
@excluded_types = [Exclude1, Exclude2]
|
1663
|
+
@all_types = @included_types + @excluded_types
|
1664
|
+
excluded_pointcut1 = Pointcut.new :type => Exclude1, :method => :doit
|
1665
|
+
excluded_pointcut2 = Pointcut.new :type => Exclude2, :method => :doit
|
1666
|
+
@excluded_pointcuts = [excluded_pointcut1, excluded_pointcut2]
|
1667
|
+
pointcut1 = Pointcut.new :types => @included_types, :method => :doit
|
1668
|
+
pointcut2 = Pointcut.new :types => @excluded_types, :method => :doit
|
1669
|
+
@all_pointcuts = [pointcut1, pointcut2]
|
1615
1670
|
end
|
1616
|
-
|
1671
|
+
|
1672
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_pointcut(s) => [pcs], where [pcs] are the list of pointcuts for the types and methods to exclude" do
|
1673
|
+
aspect = nil
|
1617
1674
|
advice_called = false
|
1618
|
-
|
1619
|
-
|
1675
|
+
aspect = Aspect.new :before, :pointcuts => @all_pointcuts, :exclude_pointcuts => @excluded_pointcuts do |jp, obj, *args|
|
1676
|
+
advice_called = true
|
1677
|
+
@excluded_types.should_not include(jp.target_type)
|
1678
|
+
end
|
1679
|
+
@included_types.each do |type|
|
1680
|
+
advice_called = false
|
1681
|
+
type.new(1).doit
|
1682
|
+
advice_called.should be_true
|
1683
|
+
end
|
1684
|
+
@excluded_types.each do |type|
|
1685
|
+
advice_called = false
|
1686
|
+
type.new(1).doit
|
1687
|
+
advice_called.should_not be_true
|
1688
|
+
end
|
1689
|
+
aspect.unadvise
|
1620
1690
|
end
|
1621
|
-
aspect.unadvise
|
1622
1691
|
end
|
1623
|
-
end
|
1624
1692
|
|
1625
|
-
describe Aspect, ".new (with type-based :pointcut(s) and :exclude_type(s) parameter)" do
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
advice_called = false
|
1633
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_types => excluded_types do |jp, obj, *args|
|
1634
|
-
advice_called = true
|
1635
|
-
excluded_types.should_not include(jp.target_type)
|
1636
|
-
end
|
1637
|
-
|
1638
|
-
included_types.each do |type|
|
1693
|
+
describe Aspect, ".new (with type-based :pointcut(s) and :exclude_type(s) parameter)" do
|
1694
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s) => [types], where join points with [types] are excluded" do
|
1695
|
+
included_types = [DontExclude1, DontExclude2]
|
1696
|
+
excluded_types = [Exclude1, Exclude2]
|
1697
|
+
pointcut1 = Pointcut.new :types => included_types, :method => :doit
|
1698
|
+
pointcut2 = Pointcut.new :types => excluded_types, :method => :doit
|
1699
|
+
aspect = nil
|
1639
1700
|
advice_called = false
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
advice_called = false
|
1645
|
-
type.new(1).doit
|
1646
|
-
advice_called.should_not be_true
|
1647
|
-
end
|
1648
|
-
aspect.unadvise
|
1649
|
-
end
|
1650
|
-
end
|
1701
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_types => excluded_types do |jp, obj, *args|
|
1702
|
+
advice_called = true
|
1703
|
+
excluded_types.should_not include(jp.target_type)
|
1704
|
+
end
|
1651
1705
|
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
jp.target_type.should == ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod
|
1706
|
+
included_types.each do |type|
|
1707
|
+
advice_called = false
|
1708
|
+
type.new(1).doit
|
1709
|
+
advice_called.should be_true
|
1710
|
+
end
|
1711
|
+
excluded_types.each do |type|
|
1712
|
+
advice_called = false
|
1713
|
+
type.new(1).doit
|
1714
|
+
advice_called.should_not be_true
|
1662
1715
|
end
|
1716
|
+
aspect.unadvise
|
1663
1717
|
end
|
1664
|
-
aspect.unadvise
|
1665
1718
|
end
|
1666
|
-
end
|
1667
1719
|
|
1668
|
-
describe Aspect, ".new (with type-based :pointcut(s) and :exclude_type(s)
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1720
|
+
describe Aspect, ".new (with type-based :pointcut(s) and :exclude_type(s)_and_ancestors parameter)" do
|
1721
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s)_and_ancestors => [types], where join points with [types] are excluded" do
|
1722
|
+
excluded_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1723
|
+
types = excluded_types + [ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod]
|
1724
|
+
pointcut1 = Pointcut.new :types => types, :method => :all, :method_options => [:exclude_ancestor_methods]
|
1725
|
+
advice_called = false
|
1726
|
+
aspect = Aspect.new :before, :pointcuts => pointcut1, :exclude_types_and_ancestors => excluded_types do |jp, obj, *args|; end
|
1727
|
+
aspect.pointcuts.each do |pc|
|
1728
|
+
pc.join_points_matched.each do |jp|
|
1729
|
+
jp.target_type.should == ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod
|
1730
|
+
end
|
1731
|
+
end
|
1732
|
+
aspect.unadvise
|
1733
|
+
end
|
1677
1734
|
end
|
1678
|
-
end
|
1679
|
-
|
1680
1735
|
|
1681
|
-
describe Aspect, ".new (with
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
exclude1 = DontExclude1.new(3)
|
1687
|
-
exclude2 = DontExclude1.new(4)
|
1688
|
-
included_objects = [dontExclude1, dontExclude2]
|
1689
|
-
excluded_objects = [exclude1, exclude2]
|
1690
|
-
pointcut1 = Pointcut.new :objects => included_objects, :method => :doit
|
1691
|
-
pointcut2 = Pointcut.new :objects => excluded_objects, :method => :doit
|
1692
|
-
aspect = nil
|
1693
|
-
advice_called = false
|
1694
|
-
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_objects => excluded_objects do |jp, obj, *args|
|
1695
|
-
advice_called = true
|
1696
|
-
excluded_objects.should_not include(obj)
|
1697
|
-
end
|
1698
|
-
included_objects.each do |object|
|
1736
|
+
describe Aspect, ".new (with type-based :pointcut(s) and :exclude_type(s)_and_descendents parameter)" do
|
1737
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_type(s)_and_descendents => [types], where join points with [types] are excluded" do
|
1738
|
+
excluded_types = [ClassWithPublicInstanceMethod, ModuleWithPublicInstanceMethod]
|
1739
|
+
types = excluded_types + [ClassDerivedFromClassIncludingModuleWithPublicInstanceMethod]
|
1740
|
+
pointcut1 = Pointcut.new :types => types, :method => :all, :method_options => [:exclude_ancestor_methods]
|
1699
1741
|
advice_called = false
|
1700
|
-
|
1701
|
-
|
1742
|
+
aspect = Aspect.new :before, :pointcuts => pointcut1, :exclude_types_and_descendents => excluded_types, :ignore_no_matching_join_points => true do |jp, obj, *args|; end
|
1743
|
+
aspect.pointcuts.size.should == 0
|
1744
|
+
aspect.unadvise
|
1702
1745
|
end
|
1703
|
-
|
1746
|
+
end
|
1747
|
+
|
1748
|
+
describe Aspect, ".new (with object-based :pointcut(s) and :exclude_object(s) or :exclude_method(s) parameter)" do
|
1749
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_object(s) => [objects], where join points with [objects] are excluded" do
|
1750
|
+
dontExclude1 = DontExclude1.new(1)
|
1751
|
+
dontExclude2 = DontExclude1.new(2)
|
1752
|
+
exclude1 = DontExclude1.new(3)
|
1753
|
+
exclude2 = DontExclude1.new(4)
|
1754
|
+
included_objects = [dontExclude1, dontExclude2]
|
1755
|
+
excluded_objects = [exclude1, exclude2]
|
1756
|
+
pointcut1 = Pointcut.new :objects => included_objects, :method => :doit
|
1757
|
+
pointcut2 = Pointcut.new :objects => excluded_objects, :method => :doit
|
1758
|
+
aspect = nil
|
1704
1759
|
advice_called = false
|
1705
|
-
|
1706
|
-
|
1760
|
+
aspect = Aspect.new :before, :pointcuts => [pointcut1, pointcut2], :exclude_objects => excluded_objects do |jp, obj, *args|
|
1761
|
+
advice_called = true
|
1762
|
+
excluded_objects.should_not include(obj)
|
1763
|
+
end
|
1764
|
+
included_objects.each do |object|
|
1765
|
+
advice_called = false
|
1766
|
+
object.doit
|
1767
|
+
advice_called.should be_true
|
1768
|
+
end
|
1769
|
+
excluded_objects.each do |object|
|
1770
|
+
advice_called = false
|
1771
|
+
object.doit
|
1772
|
+
advice_called.should_not be_true
|
1773
|
+
end
|
1774
|
+
aspect.unadvise
|
1707
1775
|
end
|
1708
|
-
aspect.unadvise
|
1709
1776
|
end
|
1710
|
-
end
|
1711
1777
|
|
1712
|
-
describe Aspect, ".new (with :method(s) and :exclude_method(s) parameter)" do
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1778
|
+
describe Aspect, ".new (with :method(s) and :exclude_method(s) parameter)" do
|
1779
|
+
before :each do
|
1780
|
+
@dontExclude1 = DontExclude1.new(1)
|
1781
|
+
@dontExclude2 = DontExclude1.new(2)
|
1782
|
+
@exclude1 = DontExclude1.new(3)
|
1783
|
+
@exclude2 = DontExclude1.new(4)
|
1784
|
+
@exclude1c = Exclude1c.new(5)
|
1785
|
+
@included_objects = [@dontExclude1, @dontExclude2, @exclude1, @exclude2]
|
1786
|
+
@excluded_objects = [@exclude1c]
|
1787
|
+
@included_types = [DontExclude1, DontExclude2, Exclude1, Exclude2]
|
1788
|
+
@excluded_types = [Exclude1c]
|
1789
|
+
@excluded_methods = [:doit3]
|
1790
|
+
@pointcut1 = Pointcut.new :objects => @included_objects, :method => /doit/
|
1791
|
+
@pointcut2 = Pointcut.new :objects => @excluded_objects, :method => /doit/
|
1792
|
+
@pointcut3 = Pointcut.new :types => @included_types, :method => /doit/
|
1793
|
+
@pointcut4 = Pointcut.new :types => @excluded_types, :method => /doit/
|
1794
|
+
end
|
1729
1795
|
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1796
|
+
def do_method_exclusion parameter_hash, types_were_specified
|
1797
|
+
parameter_hash[:before] = ''
|
1798
|
+
parameter_hash[:exclude_methods] = :doit3
|
1799
|
+
aspect = nil
|
1800
|
+
advice_called = false
|
1801
|
+
aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1802
|
+
advice_called = true
|
1803
|
+
@excluded_methods.should_not include(jp.method_name)
|
1804
|
+
end
|
1805
|
+
if types_were_specified
|
1806
|
+
(@included_types + @excluded_types).each do |type|
|
1807
|
+
advice_called = false
|
1808
|
+
type.new(1).doit
|
1809
|
+
advice_called.should be_true
|
1810
|
+
end
|
1811
|
+
@excluded_types.each do |type|
|
1812
|
+
advice_called = false
|
1813
|
+
type.new(1).doit3
|
1814
|
+
advice_called.should_not be_true
|
1815
|
+
end
|
1816
|
+
end
|
1817
|
+
(@included_objects + @excluded_objects).each do |object|
|
1741
1818
|
advice_called = false
|
1742
|
-
|
1819
|
+
object.doit
|
1743
1820
|
advice_called.should be_true
|
1744
1821
|
end
|
1745
|
-
@
|
1822
|
+
@excluded_objects.each do |object|
|
1746
1823
|
advice_called = false
|
1747
|
-
|
1824
|
+
object.doit3
|
1748
1825
|
advice_called.should_not be_true
|
1749
1826
|
end
|
1827
|
+
aspect.unadvise
|
1750
1828
|
end
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1829
|
+
|
1830
|
+
Aspect::CANONICAL_OPTIONS["exclude_methods"].each do |key|
|
1831
|
+
it "should accept :#{key} as a synonym for :exclude_methods." do
|
1832
|
+
lambda { Aspect.new :before, :pointcuts => [@pointcut1, @pointcut2, @pointcut3, @pointcut4], key.intern => :doit3, :noop => true }.should_not raise_error
|
1833
|
+
end
|
1755
1834
|
end
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1835
|
+
|
1836
|
+
it "should accept :pointcut(s) => [P1, ...], :exclude_method(s) => [methods], where join points with [methods] are excluded" do
|
1837
|
+
parameter_hash = { :pointcuts => [@pointcut1, @pointcut2, @pointcut3, @pointcut4] }
|
1838
|
+
do_method_exclusion parameter_hash, true
|
1760
1839
|
end
|
1761
|
-
aspect.unadvise
|
1762
|
-
end
|
1763
1840
|
|
1764
|
-
|
1765
|
-
|
1766
|
-
parameter_hash
|
1767
|
-
do_method_exclusion parameter_hash, true, key.intern
|
1841
|
+
it "should accept :type(s) => ..., :method(s) => ..., :exclude_method(s) => [methods], where join points with [methods] are excluded" do
|
1842
|
+
parameter_hash = { :types => (@included_types + @excluded_types), :methods => /doit/ }
|
1843
|
+
do_method_exclusion parameter_hash, true
|
1768
1844
|
end
|
1769
|
-
end
|
1770
|
-
|
1771
|
-
it "should accept :pointcut(s) => [P1, ...], :exclude_method(s) => [methods], where join points with [methods] are excluded" do
|
1772
|
-
parameter_hash = { :pointcuts => [@pointcut1, @pointcut2, @pointcut3, @pointcut4] }
|
1773
|
-
do_method_exclusion parameter_hash, true
|
1774
|
-
end
|
1775
1845
|
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1846
|
+
# it "should accept :object(s) => ..., :method(s) => ..., :exclude_method(s) => [methods], where join points with [methods] are excluded" do
|
1847
|
+
# pending "bug fix"
|
1848
|
+
# Aspect.echo = true
|
1849
|
+
# parameter_hash = { :objects => (@included_objects + @excluded_objects), :methods => /doit/ }
|
1850
|
+
# do_method_exclusion parameter_hash, false
|
1851
|
+
# Aspect.echo = false
|
1852
|
+
# end
|
1853
|
+
#
|
1854
|
+
# def do_method_exclusion2 parameter_hash, types_were_specified
|
1855
|
+
# parameter_hash[:before] = ''
|
1856
|
+
# parameter_hash[:exclude_method] = :doit3
|
1857
|
+
# parameter_hash[:method] = /doit/
|
1858
|
+
# aspect = nil
|
1859
|
+
# advice_called = false
|
1860
|
+
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1861
|
+
# advice_called = true
|
1862
|
+
# @excluded_methods.should_not include(jp.method_name)
|
1863
|
+
# end
|
1864
|
+
# (@excluded_objects).each do |object|
|
1865
|
+
# advice_called = false
|
1866
|
+
# object.doit
|
1867
|
+
# advice_called.should be_true
|
1868
|
+
# end
|
1869
|
+
# aspect.unadvise
|
1870
|
+
# end
|
1871
|
+
#
|
1872
|
+
# def buggy parameter_hash
|
1873
|
+
# parameter_hash[:before] = ''
|
1874
|
+
# parameter_hash[:exclude_method] = :doit3
|
1875
|
+
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1876
|
+
# end
|
1877
|
+
# @excluded_objects.each do |object|
|
1878
|
+
# object.doit
|
1879
|
+
# end
|
1880
|
+
# aspect.unadvise
|
1881
|
+
# end
|
1882
|
+
#
|
1883
|
+
# it "#15202 bug..." do
|
1884
|
+
# pending "bug fix"
|
1885
|
+
# @pointcut5 = Pointcut.new :types => [Exclude1, Exclude1c], :method => /doit/
|
1886
|
+
# parameter_hash = { :pointcuts => [@pointcut5] } #[@pointcut1, @pointcut2, @pointcut3, @pointcut4] }
|
1887
|
+
# buggy parameter_hash
|
1888
|
+
# parameter_hash = { :objects => (@excluded_objects), :method => /doit/ }
|
1889
|
+
# buggy parameter_hash
|
1890
|
+
# end
|
1779
1891
|
end
|
1780
|
-
|
1781
|
-
# it "should accept :object(s) => ..., :method(s) => ..., :exclude_method(s) => [methods], where join points with [methods] are excluded" do
|
1782
|
-
# pending "bug fix"
|
1783
|
-
# Aspect.echo = true
|
1784
|
-
# parameter_hash = { :objects => (@included_objects + @excluded_objects), :methods => /doit/ }
|
1785
|
-
# do_method_exclusion parameter_hash, false
|
1786
|
-
# Aspect.echo = false
|
1787
|
-
# end
|
1788
|
-
#
|
1789
|
-
# def do_method_exclusion2 parameter_hash, types_were_specified
|
1790
|
-
# parameter_hash[:before] = ''
|
1791
|
-
# parameter_hash[:exclude_method] = :doit3
|
1792
|
-
# parameter_hash[:method] = /doit/
|
1793
|
-
# aspect = nil
|
1794
|
-
# advice_called = false
|
1795
|
-
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1796
|
-
# advice_called = true
|
1797
|
-
# @excluded_methods.should_not include(jp.method_name)
|
1798
|
-
# end
|
1799
|
-
# (@excluded_objects).each do |object|
|
1800
|
-
# advice_called = false
|
1801
|
-
# object.doit
|
1802
|
-
# advice_called.should be_true
|
1803
|
-
# end
|
1804
|
-
# aspect.unadvise
|
1805
|
-
# end
|
1806
|
-
#
|
1807
|
-
# def buggy parameter_hash
|
1808
|
-
# parameter_hash[:before] = ''
|
1809
|
-
# parameter_hash[:exclude_method] = :doit3
|
1810
|
-
# aspect = Aspect.new parameter_hash do |jp, obj, *args|
|
1811
|
-
# end
|
1812
|
-
# @excluded_objects.each do |object|
|
1813
|
-
# object.doit
|
1814
|
-
# end
|
1815
|
-
# aspect.unadvise
|
1816
|
-
# end
|
1817
|
-
#
|
1818
|
-
# it "#15202 bug..." do
|
1819
|
-
# pending "bug fix"
|
1820
|
-
# @pointcut5 = Pointcut.new :types => [Exclude1, Exclude1c], :method => /doit/
|
1821
|
-
# parameter_hash = { :pointcuts => [@pointcut5] } #[@pointcut1, @pointcut2, @pointcut3, @pointcut4] }
|
1822
|
-
# buggy parameter_hash
|
1823
|
-
# parameter_hash = { :objects => (@excluded_objects), :method => /doit/ }
|
1824
|
-
# buggy parameter_hash
|
1825
|
-
# end
|
1826
1892
|
end
|