aquarium 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +35 -0
- data/MIT-LICENSE +1 -1
- data/README +66 -20
- data/Rakefile +1 -1
- data/UPGRADE +5 -0
- data/examples/aspect_design_example.rb +5 -4
- data/examples/aspect_design_example_spec.rb +6 -5
- data/examples/design_by_contract_example.rb +3 -3
- data/examples/design_by_contract_example_spec.rb +4 -4
- data/examples/method_missing_example.rb +1 -1
- data/examples/method_missing_example_spec.rb +2 -2
- data/examples/method_tracing_example.rb +3 -3
- data/examples/method_tracing_example_spec.rb +6 -6
- data/lib/aquarium/aspects/advice.rb +2 -3
- data/lib/aquarium/aspects/aspect.rb +100 -246
- data/lib/aquarium/aspects/{default_object_handler.rb → default_objects_handler.rb} +7 -6
- data/lib/aquarium/aspects/dsl/aspect_dsl.rb +2 -2
- data/lib/aquarium/aspects/pointcut.rb +190 -107
- data/lib/aquarium/finders/method_finder.rb +120 -34
- data/lib/aquarium/finders/type_finder.rb +2 -5
- data/lib/aquarium/utils.rb +1 -0
- data/lib/aquarium/utils/array_utils.rb +11 -3
- data/lib/aquarium/utils/options_utils.rb +74 -0
- data/lib/aquarium/utils/type_utils.rb +25 -11
- 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 +179 -145
- data/spec/aquarium/aspects/aspect_spec.rb +1 -1
- 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/default_objects_handler_spec.rb +147 -0
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +72 -121
- data/spec/aquarium/aspects/join_point_spec.rb +1 -1
- data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +1 -1
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +48 -47
- data/spec/aquarium/aspects/pointcut_spec.rb +727 -410
- data/spec/aquarium/extensions/hash_spec.rb +1 -1
- data/spec/aquarium/extensions/regex_spec.rb +1 -1
- data/spec/aquarium/extensions/set_spec.rb +1 -1
- data/spec/aquarium/extensions/string_spec.rb +1 -1
- data/spec/aquarium/extensions/symbol_spec.rb +1 -1
- data/spec/aquarium/extras/design_by_contract_spec.rb +1 -1
- data/spec/aquarium/finders/finder_result_spec.rb +1 -1
- data/spec/aquarium/finders/method_finder_spec.rb +49 -16
- data/spec/aquarium/finders/type_finder_spec.rb +1 -1
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +16 -1
- data/spec/aquarium/utils/array_utils_spec.rb +31 -6
- data/spec/aquarium/utils/hash_utils_spec.rb +1 -1
- data/spec/aquarium/utils/html_escaper_spec.rb +1 -1
- data/spec/aquarium/utils/logic_error_spec.rb +1 -1
- data/spec/aquarium/utils/method_utils_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/set_utils_spec.rb +1 -1
- data/spec/aquarium/utils/type_utils_spec.rb +1 -1
- metadata +9 -7
@@ -1,6 +1,6 @@
|
|
1
1
|
# Specifically tests behavior when two or more advices apply to the same join point(s).
|
2
2
|
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
4
|
require File.dirname(__FILE__) + '/../spec_example_classes'
|
5
5
|
require File.dirname(__FILE__) + '/concurrently_accessed'
|
6
6
|
require 'aquarium/aspects'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Specifically tests behavior when two or more advices apply to the same join points,
|
2
2
|
# where one advice is for the type and the other is for an object of the type.
|
3
3
|
|
4
|
-
require File.dirname(__FILE__) + '/../spec_helper
|
4
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
5
5
|
require File.dirname(__FILE__) + '/../spec_example_classes'
|
6
6
|
require File.dirname(__FILE__) + '/concurrently_accessed'
|
7
7
|
require 'aquarium/aspects'
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'aquarium/aspects/default_objects_handler'
|
3
|
+
|
4
|
+
module Aquarium
|
5
|
+
class DefaultObjectsClass
|
6
|
+
include Aquarium::Aspects::DefaultObjectsHandler
|
7
|
+
|
8
|
+
attr_reader :specification
|
9
|
+
|
10
|
+
def initialize hash = {}
|
11
|
+
@specification = hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Aquarium::Aspects::DefaultObjectsHandler, "#default_objects_given" do
|
17
|
+
it "should return an empty array if the specification contains no :default_object or :default_objects key." do
|
18
|
+
Aquarium::DefaultObjectsClass.new.default_objects_given.should == []
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return an array of objects that were specified with the :default_object key." do
|
22
|
+
defaults = ["1", "2"]
|
23
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => defaults
|
24
|
+
doc.default_objects_given.should == defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return an array of objects that were specified with the :default_objects key." do
|
28
|
+
defaults = ["1", "2"]
|
29
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => defaults
|
30
|
+
doc.default_objects_given.should == defaults
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return an array containing a single object if a single objects was specified with the :default_object key." do
|
34
|
+
default = "1"
|
35
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => default
|
36
|
+
doc.default_objects_given.should == [default]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return an array containing a single object if a single objects was specified with the :default_objects key." do
|
40
|
+
default = "1"
|
41
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => default
|
42
|
+
doc.default_objects_given.should == [default]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Aquarium::Aspects::DefaultObjectsHandler, "#default_objects_given?" do
|
47
|
+
it "should return false if the specification contains no :default_object or :default_objects key." do
|
48
|
+
Aquarium::DefaultObjectsClass.new.default_objects_given?.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return true if one or more objects were specified with the :default_object key." do
|
52
|
+
defaults = ["1", "2"]
|
53
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => defaults
|
54
|
+
doc.default_objects_given?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return true if one or more objects were specified with the :default_objects key." do
|
58
|
+
defaults = ["1", "2"]
|
59
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => defaults
|
60
|
+
doc.default_objects_given?.should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return true if a single objects was specified with the :default_object key." do
|
64
|
+
default = "1"
|
65
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => default
|
66
|
+
doc.default_objects_given?.should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return true if a single objects was specified with the :default_objects key." do
|
70
|
+
default = "1"
|
71
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => default
|
72
|
+
doc.default_objects_given?.should be_true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe Aquarium::Aspects::DefaultObjectsHandler, "#use_default_objects_if_defined" do
|
77
|
+
it "should not change the specification if no :default_object or :default_objects were defined." do
|
78
|
+
doc = Aquarium::DefaultObjectsClass.new
|
79
|
+
doc.use_default_objects_if_defined
|
80
|
+
doc.specification.should == {}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set the :objects in the specification to an array of objects if :default_object was defined with an array of objects." do
|
84
|
+
defaults = ["1", "2"]
|
85
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => defaults
|
86
|
+
doc.use_default_objects_if_defined
|
87
|
+
doc.specification.should == {:default_object => defaults, :objects => defaults}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should set the :objects in the specification to an array of objects if :default_objects was defined with an array of objects." do
|
91
|
+
defaults = ["1", "2"]
|
92
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => defaults
|
93
|
+
doc.use_default_objects_if_defined
|
94
|
+
doc.specification.should == {:default_objects => defaults, :objects => defaults}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should set the :objects in the specification to an array with one object if :default_object was defined with one object." do
|
98
|
+
default = "1"
|
99
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => default
|
100
|
+
doc.use_default_objects_if_defined
|
101
|
+
doc.specification.should == {:default_object => default, :objects => [default]}
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should set the :objects in the specification to an array with one object if :default_objects was defined with one object." do
|
105
|
+
default = "1"
|
106
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => default
|
107
|
+
doc.use_default_objects_if_defined
|
108
|
+
doc.specification.should == {:default_objects => default, :objects => [default]}
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should set the :types in the specification to an array of types if :default_object was defined with an array of types." do
|
112
|
+
defaults = [String, Aquarium::DefaultObjectsClass]
|
113
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => defaults
|
114
|
+
doc.use_default_objects_if_defined
|
115
|
+
doc.specification.should == {:default_object => defaults, :types => defaults}
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should set the :types in the specification to an array of types if :default_objects was defined with an array of types." do
|
119
|
+
defaults = [String, Aquarium::DefaultObjectsClass]
|
120
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => defaults
|
121
|
+
doc.use_default_objects_if_defined
|
122
|
+
doc.specification.should == {:default_objects => defaults, :types => defaults}
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should set the :types in the specification to an array with one type if :default_object was defined with one type." do
|
126
|
+
default = String
|
127
|
+
doc = Aquarium::DefaultObjectsClass.new :default_object => default
|
128
|
+
doc.use_default_objects_if_defined
|
129
|
+
doc.specification.should == {:default_object => default, :types => [default]}
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should set the :types in the specification to an array with one type if :default_objects was defined with one type." do
|
133
|
+
default = String
|
134
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => default
|
135
|
+
doc.use_default_objects_if_defined
|
136
|
+
doc.specification.should == {:default_objects => default, :types => [default]}
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should set the :objects and :types in the specification to arrays of the corresponding objects and types if :default_objects was defined with objects and types." do
|
140
|
+
defaults = [String, Aquarium::DefaultObjectsClass, "1", "2"]
|
141
|
+
doc = Aquarium::DefaultObjectsClass.new :default_objects => defaults
|
142
|
+
doc.use_default_objects_if_defined
|
143
|
+
doc.specification.should == {:default_objects => defaults, :types => [String, Aquarium::DefaultObjectsClass], :objects => ["1", "2"]}
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require File.dirname(__FILE__) + '/../../spec_example_classes'
|
3
3
|
require 'aquarium/aspects/dsl/aspect_dsl'
|
4
4
|
|
@@ -16,8 +16,8 @@ describe "DSL method #before" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should be equivalent to advise :before." do
|
19
|
-
@aspects << DSLClass.advise(:before, :noop, :pointcut => {:
|
20
|
-
@aspects << DSLClass.before( :noop, :pointcut => {:
|
19
|
+
@aspects << DSLClass.advise(:before, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
20
|
+
@aspects << DSLClass.before( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
21
21
|
@aspects[1].should == @aspects[0]
|
22
22
|
end
|
23
23
|
end
|
@@ -32,8 +32,8 @@ describe "DSL method #after" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should be equivalent to advise :after." do
|
35
|
-
@aspects << DSLClass.advise(:after, :noop, :pointcut => {:
|
36
|
-
@aspects << DSLClass.after( :noop, :pointcut => {:
|
35
|
+
@aspects << DSLClass.advise(:after, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
36
|
+
@aspects << DSLClass.after( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
37
37
|
@aspects[1].should == @aspects[0]
|
38
38
|
end
|
39
39
|
end
|
@@ -49,8 +49,8 @@ describe "DSL method #after_raising_within_or_returning_from" do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should be equivalent to advise :after." do
|
52
|
-
@aspects << DSLClass.after( :noop, :pointcut => {:
|
53
|
-
@aspects << DSLClass.after_raising_within_or_returning_from(:noop, :pointcut => {:
|
52
|
+
@aspects << DSLClass.after( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
53
|
+
@aspects << DSLClass.after_raising_within_or_returning_from(:noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
54
54
|
@aspects[1].should == @aspects[0]
|
55
55
|
end
|
56
56
|
end
|
@@ -66,8 +66,8 @@ describe "DSL method #after_returning" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should be equivalent to advise :after_returning." do
|
69
|
-
@aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:
|
70
|
-
@aspects << DSLClass.after_returning( :noop, :pointcut => {:
|
69
|
+
@aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
70
|
+
@aspects << DSLClass.after_returning( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
71
71
|
@aspects[1].should == @aspects[0]
|
72
72
|
end
|
73
73
|
end
|
@@ -83,8 +83,8 @@ describe "DSL method #after_returning_from" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should be equivalent to advise :after_returning." do
|
86
|
-
@aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:
|
87
|
-
@aspects << DSLClass.after_returning_from( :noop, :pointcut => {:
|
86
|
+
@aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
87
|
+
@aspects << DSLClass.after_returning_from( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
88
88
|
@aspects[1].should == @aspects[0]
|
89
89
|
end
|
90
90
|
end
|
@@ -103,8 +103,8 @@ describe "DSL method #after_raising" do
|
|
103
103
|
class ThrowsUp
|
104
104
|
def tosses_cookies *args; raise Exception.new(args.inspect); end
|
105
105
|
end
|
106
|
-
@aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:
|
107
|
-
@aspects << DSLClass.after_raising( :noop, :pointcut => {:
|
106
|
+
@aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
|
107
|
+
@aspects << DSLClass.after_raising( :noop, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
|
108
108
|
@aspects[1].should == @aspects[0]
|
109
109
|
end
|
110
110
|
end
|
@@ -123,8 +123,8 @@ describe "DSL method #after_raising_within" do
|
|
123
123
|
class ThrowsUp
|
124
124
|
def tosses_cookies *args; raise Exception.new(args.inspect); end
|
125
125
|
end
|
126
|
-
@aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:
|
127
|
-
@aspects << DSLClass.after_raising_within( :noop, :pointcut => {:
|
126
|
+
@aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
|
127
|
+
@aspects << DSLClass.after_raising_within( :noop, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
|
128
128
|
@aspects[1].should == @aspects[0]
|
129
129
|
end
|
130
130
|
end
|
@@ -140,8 +140,8 @@ describe "DSL method #before_and_after" do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should be equivalent to advise :before, :after." do
|
143
|
-
@aspects << DSLClass.advise(:before, :after, :noop, :pointcut => {:
|
144
|
-
@aspects << DSLClass.before_and_after(:noop, :pointcut => {:
|
143
|
+
@aspects << DSLClass.advise(:before, :after, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
144
|
+
@aspects << DSLClass.before_and_after( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
145
145
|
@aspects[1].should == @aspects[0]
|
146
146
|
end
|
147
147
|
end
|
@@ -157,8 +157,8 @@ describe "DSL method #before_and_after_raising_within_or_returning_from" do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should be equivalent to advise :before and advise :after." do
|
160
|
-
@aspects << DSLClass.advise(:before, :after,
|
161
|
-
@aspects << DSLClass.before_and_after_raising_within_or_returning_from(:noop, :pointcut => {:
|
160
|
+
@aspects << DSLClass.advise(:before, :after, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
161
|
+
@aspects << DSLClass.before_and_after_raising_within_or_returning_from(:noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
162
162
|
@aspects[1].should == @aspects[0]
|
163
163
|
end
|
164
164
|
end
|
@@ -174,8 +174,8 @@ describe "DSL method #before_and_after_returning" do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should be equivalent to advise :before and advise :after_returning." do
|
177
|
-
@aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:
|
178
|
-
@aspects << DSLClass.before_and_after_returning( :noop, :pointcut => {:
|
177
|
+
@aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
178
|
+
@aspects << DSLClass.before_and_after_returning( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
179
179
|
@aspects[1].should == @aspects[0]
|
180
180
|
end
|
181
181
|
end
|
@@ -191,8 +191,8 @@ describe "DSL method #before_and_after_returning_from" do
|
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should be equivalent to advise :before and advise :after_returning." do
|
194
|
-
@aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:
|
195
|
-
@aspects << DSLClass.before_and_after_returning_from(:noop, :pointcut => {:
|
194
|
+
@aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
195
|
+
@aspects << DSLClass.before_and_after_returning_from( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
196
196
|
@aspects[1].should == @aspects[0]
|
197
197
|
end
|
198
198
|
end
|
@@ -208,8 +208,8 @@ describe "DSL method #before_and_after_raising" do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should be equivalent to advise :before and advise :after_raising." do
|
211
|
-
@aspects << DSLClass.advise(:before, :after_raising, :noop, :pointcut => {:
|
212
|
-
@aspects << DSLClass.before_and_after_raising(:noop, :pointcut => {:
|
211
|
+
@aspects << DSLClass.advise(:before, :after_raising, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
212
|
+
@aspects << DSLClass.before_and_after_raising( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
213
213
|
@aspects[1].should == @aspects[0]
|
214
214
|
end
|
215
215
|
end
|
@@ -225,8 +225,8 @@ describe "DSL method #around" do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should be equivalent to advise :around." do
|
228
|
-
@aspects << DSLClass.advise(:around, :noop, :pointcut => {:
|
229
|
-
@aspects << DSLClass.around( :noop, :pointcut => {:
|
228
|
+
@aspects << DSLClass.advise(:around, :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
229
|
+
@aspects << DSLClass.around( :noop, :pointcut => {:calls_to => :public_watchful_method, :in_type => Watchful}, &@advice)
|
230
230
|
@aspects[1].should == @aspects[0]
|
231
231
|
end
|
232
232
|
end
|
@@ -243,11 +243,11 @@ describe "DSL method #advise, when determining the \"self\" to advise," do
|
|
243
243
|
class Watchful1
|
244
244
|
include Aquarium::Aspects::DSL::AspectDSL
|
245
245
|
@@watchful = Watchful1.new
|
246
|
-
@@aspect = after(:
|
246
|
+
@@aspect = after(:invoking => :public_watchful_method, :on_object => @@watchful) {|jp, obj, *args|}
|
247
247
|
def self.watchful; @@watchful; end
|
248
248
|
def self.aspect; @@aspect; end
|
249
249
|
end
|
250
|
-
@aspects <<
|
250
|
+
@aspects << Watchful1.after(:invoking => :public_watchful_method, :on_object => Watchful1.watchful) {|jp, obj, *args|}
|
251
251
|
@aspects << Watchful1.aspect
|
252
252
|
@aspects[1].join_points_matched.should == @aspects[0].join_points_matched
|
253
253
|
@aspects[1].pointcuts.should == @aspects[0].pointcuts
|
@@ -256,10 +256,10 @@ describe "DSL method #advise, when determining the \"self\" to advise," do
|
|
256
256
|
it "should ignore the default object \"self\" when a :type is specified." do
|
257
257
|
class Watchful2
|
258
258
|
include Aquarium::Aspects::DSL::AspectDSL
|
259
|
-
@@aspect = after(:
|
259
|
+
@@aspect = after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
|
260
260
|
def self.aspect; @@aspect; end
|
261
261
|
end
|
262
|
-
@aspects <<
|
262
|
+
@aspects << Watchful2.after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
|
263
263
|
@aspects << Watchful2.aspect
|
264
264
|
@aspects[1].join_points_matched.should == @aspects[0].join_points_matched
|
265
265
|
@aspects[1].pointcuts.should == @aspects[0].pointcuts
|
@@ -282,7 +282,7 @@ describe "DSL method #advise, when determining the type or object to advise," do
|
|
282
282
|
end
|
283
283
|
|
284
284
|
it "should infer the type as \"self\" when no :object, :type, or :pointcut is specified." do
|
285
|
-
@aspects <<
|
285
|
+
@aspects << WatchfulSelf.after(:calls_to => :public_watchful_method, :in_type => WatchfulSelf) {|jp, obj, *args|}
|
286
286
|
class WatchfulSelf
|
287
287
|
@@aspect = after(:method => :public_watchful_method) {|jp, obj, *args|}
|
288
288
|
end
|
@@ -294,10 +294,9 @@ describe "DSL method #advise, when determining the type or object to advise," do
|
|
294
294
|
it "should infer the object as \"self\" when no :object, :type, or :pointcut is specified." do
|
295
295
|
watchful_self = WatchfulSelf.new
|
296
296
|
watchful_self.extend Aquarium::Aspects::DSL::AspectDSL
|
297
|
-
@aspects <<
|
297
|
+
@aspects << WatchfulSelf.advise(:after, :pointcut => {:invoking => :public_watchful_method, :on_object => watchful_self}) {|jp, obj, *args|}
|
298
298
|
@aspects << watchful_self.after(:method => :public_watchful_method) {|jp, obj, *args|}
|
299
299
|
@aspects[1].join_points_matched.should == @aspects[0].join_points_matched
|
300
|
-
@aspects[1].pointcuts.should == @aspects[0].pointcuts
|
301
300
|
end
|
302
301
|
|
303
302
|
it "should infer no types or objects if a :pointcut => {...} parameter is used and it does not specify a type or object." do
|
@@ -357,7 +356,7 @@ describe "DSL method #advise, when determining instance or class methods to advi
|
|
357
356
|
def public_watchful_method *args; end
|
358
357
|
end
|
359
358
|
advice_called = 0
|
360
|
-
WatchfulExampleWithSeparateAdviseCall2.advise :before, :
|
359
|
+
WatchfulExampleWithSeparateAdviseCall2.advise :before, :sending_messages_to => /public_watchful_method/, :on_types => WatchfulExampleWithSeparateAdviseCall2, :restricting_methods_to =>[:instance_methods] do |jp, obj, *args|
|
361
360
|
advice_called += 1
|
362
361
|
end
|
363
362
|
WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a1, :a2
|
@@ -375,7 +374,7 @@ describe "DSL method #advise, when determining instance or class methods to advi
|
|
375
374
|
def public_watchful_method *args; end
|
376
375
|
end
|
377
376
|
advice_called = 0
|
378
|
-
WatchfulExampleWithSeparateAdviseCall3.advise :before, :
|
377
|
+
WatchfulExampleWithSeparateAdviseCall3.advise :before, :calling => /public_watchful_method/, :restricting_methods_to =>[:class_methods] do |jp, obj, *args|
|
379
378
|
advice_called += 1
|
380
379
|
end
|
381
380
|
WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a1, :a2
|
@@ -428,102 +427,54 @@ describe "DSL methods for the advice kind, when determining instance or class me
|
|
428
427
|
end
|
429
428
|
|
430
429
|
describe "Synonyms for :types" do
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
@aspects << DSLClass.after(:noop, :type => Watchful, :methods => :public_watchful_method, &@advice)
|
441
|
-
@aspects[1].should == @aspects[0]
|
442
|
-
end
|
443
|
-
|
444
|
-
it ":within_types is a synonym for :types" do
|
445
|
-
@aspects << DSLClass.after(:noop, :within_type => Watchful, :methods => :public_watchful_method, &@advice)
|
446
|
-
@aspects[1].should == @aspects[0]
|
447
|
-
end
|
448
|
-
|
449
|
-
it ":within_types is a synonym for :types" do
|
450
|
-
@aspects << DSLClass.after(:noop, :within_types => Watchful, :methods => :public_watchful_method, &@advice)
|
451
|
-
@aspects[1].should == @aspects[0]
|
430
|
+
Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["types"].each do |key|
|
431
|
+
it "should accept :#{key} as a synonym for :types." do
|
432
|
+
advice = proc {|jp, obj, *args| "advice"}
|
433
|
+
aspect1 = DSLClass.after :noop, :calls_to => :public_watchful_method, :types => Watchful, &advice
|
434
|
+
aspect2 = DSLClass.after :noop, :calls_to => :public_watchful_method, key.intern => Watchful, &advice
|
435
|
+
aspect2.should == aspect1
|
436
|
+
aspect1.unadvise
|
437
|
+
aspect2.unadvise
|
438
|
+
end
|
452
439
|
end
|
453
440
|
end
|
454
441
|
|
455
442
|
describe "Synonyms for :objects" do
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
@aspects << DSLClass.after(:noop, :object => @watchful, :methods => :public_watchful_method, &@advice)
|
466
|
-
@aspects[1].should == @aspects[0]
|
467
|
-
end
|
468
|
-
|
469
|
-
it ":within_objects is a synonym for :objects" do
|
470
|
-
@aspects << DSLClass.after(:noop, :within_object => @watchful, :methods => :public_watchful_method, &@advice)
|
471
|
-
@aspects[1].should == @aspects[0]
|
472
|
-
end
|
473
|
-
|
474
|
-
it ":within_objects is a synonym for :objects" do
|
475
|
-
@aspects << DSLClass.after(:noop, :within_objects => @watchful, :methods => :public_watchful_method, &@advice)
|
476
|
-
@aspects[1].should == @aspects[0]
|
443
|
+
Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["objects"].each do |key|
|
444
|
+
it "should accept :#{key} as a synonym for :objects." do
|
445
|
+
advice = proc {|jp, obj, *args| "advice"}
|
446
|
+
aspect1 = DSLClass.after :noop, :calls_to => :public_watchful_method, :objects => @watchful, &advice
|
447
|
+
aspect2 = DSLClass.after :noop, :calls_to => :public_watchful_method, key.intern => @watchful, &advice
|
448
|
+
aspect2.should == aspect1
|
449
|
+
aspect1.unadvise
|
450
|
+
aspect2.unadvise
|
451
|
+
end
|
477
452
|
end
|
478
453
|
end
|
479
454
|
|
480
455
|
describe "Synonyms for :methods" do
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
@aspects << DSLClass.after(:noop, :object => @watchful, :method => :public_watchful_method, &@advice)
|
491
|
-
@aspects[1].should == @aspects[0]
|
492
|
-
end
|
493
|
-
|
494
|
-
it ":within_methods is a synonym for :methods" do
|
495
|
-
@aspects << DSLClass.after(:noop, :within_object => @watchful, :within_methods => :public_watchful_method, &@advice)
|
496
|
-
@aspects[1].should == @aspects[0]
|
497
|
-
end
|
498
|
-
|
499
|
-
it ":within_methods is a synonym for :methods" do
|
500
|
-
@aspects << DSLClass.after(:noop, :within_objects => @watchful, :within_method => :public_watchful_method, &@advice)
|
501
|
-
@aspects[1].should == @aspects[0]
|
456
|
+
Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["methods"].each do |key|
|
457
|
+
it "should accept :#{key} as a synonym for :methods." do
|
458
|
+
advice = proc {|jp, obj, *args| "advice"}
|
459
|
+
aspect1 = DSLClass.after :noop, :methods => :public_watchful_method, :in_types => Watchful, &advice
|
460
|
+
aspect2 = DSLClass.after :noop, key.intern => :public_watchful_method, :in_types => Watchful, &advice
|
461
|
+
aspect2.should == aspect1
|
462
|
+
aspect1.unadvise
|
463
|
+
aspect2.unadvise
|
464
|
+
end
|
502
465
|
end
|
503
466
|
end
|
504
467
|
|
505
|
-
describe "Synonyms for :
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
@aspects << DSLClass.after(:noop, :pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
|
516
|
-
@aspects[1].should == @aspects[0]
|
517
|
-
end
|
518
|
-
|
519
|
-
it "should accept :within_pointcuts as a synonym for :pointcut." do
|
520
|
-
@aspects << DSLClass.after(:noop, :within_pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
|
521
|
-
@aspects[1].should == @aspects[0]
|
522
|
-
end
|
523
|
-
|
524
|
-
it "should accept :within_pointcut as a synonym for :pointcut." do
|
525
|
-
@aspects << DSLClass.after(:noop, :within_pointcut => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
|
526
|
-
@aspects[1].should == @aspects[0]
|
468
|
+
describe "Synonyms for :pointcuts" do
|
469
|
+
Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["pointcuts"].each do |key|
|
470
|
+
it "should accept :#{key} as a synonym for :pointcuts." do
|
471
|
+
advice = proc {|jp, obj, *args| "advice"}
|
472
|
+
aspect1 = DSLClass.after :noop, :pointcuts => {:calls_to => :public_watchful_method, :within_objects => @watchful}, &advice
|
473
|
+
aspect2 = DSLClass.after :noop, key.intern => {:calls_to => :public_watchful_method, :within_objects => @watchful}, &advice
|
474
|
+
aspect2.should == aspect1
|
475
|
+
aspect1.unadvise
|
476
|
+
aspect2.unadvise
|
477
|
+
end
|
527
478
|
end
|
528
479
|
end
|
529
480
|
|