aquarium 0.1.0 → 0.1.5

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.
Files changed (42) hide show
  1. data/CHANGES +53 -0
  2. data/README +20 -4
  3. data/Rakefile +19 -4
  4. data/UPGRADE +41 -1
  5. data/examples/aspect_design_example.rb +4 -1
  6. data/examples/aspect_design_example_spec.rb +41 -0
  7. data/examples/design_by_contract_example.rb +2 -3
  8. data/examples/design_by_contract_example_spec.rb +92 -0
  9. data/examples/method_missing_example.rb +1 -1
  10. data/examples/method_missing_example_spec.rb +59 -0
  11. data/examples/method_tracing_example.rb +4 -2
  12. data/examples/method_tracing_example_spec.rb +141 -0
  13. data/lib/aquarium/aspects/advice.rb +2 -2
  14. data/lib/aquarium/aspects/aspect.rb +20 -35
  15. data/lib/aquarium/aspects/dsl.rb +2 -1
  16. data/lib/aquarium/aspects/dsl/aspect_dsl.rb +12 -8
  17. data/lib/aquarium/aspects/dsl/object_dsl.rb +8 -0
  18. data/lib/aquarium/aspects/join_point.rb +16 -10
  19. data/lib/aquarium/aspects/pointcut.rb +3 -3
  20. data/lib/aquarium/extras/design_by_contract.rb +20 -11
  21. data/lib/aquarium/utils.rb +1 -0
  22. data/lib/aquarium/utils/method_utils.rb +41 -0
  23. data/lib/aquarium/utils/name_utils.rb +35 -0
  24. data/lib/aquarium/utils/type_utils.rb +9 -0
  25. data/lib/aquarium/version.rb +3 -5
  26. data/rake_tasks/examples.rake +1 -1
  27. data/spec/aquarium/aspects/aspect_invocation_spec.rb +30 -28
  28. data/spec/aquarium/aspects/aspect_spec.rb +90 -0
  29. data/spec/aquarium/aspects/concurrent_aspects_spec.rb +5 -3
  30. data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +3 -1
  31. data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +174 -110
  32. data/spec/aquarium/aspects/join_point_spec.rb +120 -19
  33. data/spec/aquarium/aspects/pointcut_spec.rb +24 -14
  34. data/spec/aquarium/extras/design_by_contract_spec.rb +3 -0
  35. data/spec/aquarium/finders/finder_result_spec.rb +1 -1
  36. data/spec/aquarium/finders/method_finder_spec.rb +3 -4
  37. data/spec/aquarium/spec_example_classes.rb +4 -0
  38. data/spec/aquarium/utils/method_utils_spec.rb +124 -1
  39. data/spec/aquarium/utils/name_utils_spec.rb +56 -0
  40. data/spec/aquarium/utils/type_utils_spec.rb +17 -0
  41. metadata +12 -4
  42. data/spec/aquarium/finders/method_sorting_spec.rb +0 -16
@@ -5,6 +5,8 @@ require File.dirname(__FILE__) + '/../spec_example_classes'
5
5
  require File.dirname(__FILE__) + '/concurrently_accessed'
6
6
  require 'aquarium/aspects'
7
7
 
8
+ include Aquarium::Aspects
9
+
8
10
  module ConcurrentAspectsSpecSupport
9
11
  def add_m_then_remove_n_aspects_and_run iteration, for_type
10
12
  reset_attrs
@@ -69,11 +71,11 @@ module ConcurrentAspectsSpecSupport
69
71
  method = @advice_kinds[n] == :after_raising ? :invoke_raises : :invoke
70
72
  @advice_invocation_counts[n] = 0
71
73
  if for_type
72
- pointcut = Aquarium::Aspects::Pointcut.new(:methods => method, :type => ConcurrentlyAccessed)
74
+ pointcut = Pointcut.new(:methods => method, :type => ConcurrentlyAccessed)
73
75
  else
74
- pointcut = Aquarium::Aspects::Pointcut.new(:methods => method, :object => @accessed)
76
+ pointcut = Pointcut.new(:methods => method, :object => @accessed)
75
77
  end
76
- @aspects[n] = advise @advice_kinds[n], :pointcut => pointcut do |jp, *args|
78
+ @aspects[n] = Aspect.new @advice_kinds[n], :pointcut => pointcut do |jp, *args|
77
79
  @contexts[n] = jp.context
78
80
  @argss[n] = *args
79
81
  @advice_invocation_counts[n] += 1
@@ -6,8 +6,10 @@ require File.dirname(__FILE__) + '/../spec_example_classes'
6
6
  require File.dirname(__FILE__) + '/concurrently_accessed'
7
7
  require 'aquarium/aspects'
8
8
 
9
+ include Aquarium::Aspects
10
+
9
11
  def make_aspect method, advice_kind, type_or_object_key, type_or_object
10
- advise(advice_kind, :pointcut => {type_or_object_key => type_or_object, :method => method}) do |jp, *args|
12
+ Aspect.new advice_kind, :pointcut => {type_or_object_key => type_or_object, :method => method} do |jp, *args|
11
13
  @invoked << type_or_object_key
12
14
  jp.proceed if advice_kind == :around
13
15
  end
@@ -2,7 +2,11 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
  require File.dirname(__FILE__) + '/../../spec_example_classes'
3
3
  require 'aquarium/aspects/dsl/aspect_dsl'
4
4
 
5
- describe Object, "#before" do
5
+ class DSLClass
6
+ include Aquarium::Aspects::DSL::AspectDSL
7
+ end
8
+
9
+ describe "DSL method #before" do
6
10
  before :each do
7
11
  @advice = proc {|jp,*args| "advice"}
8
12
  @aspects = []
@@ -12,13 +16,13 @@ describe Object, "#before" do
12
16
  end
13
17
 
14
18
  it "should be equivalent to advise :before." do
15
- @aspects << advise(:before, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
16
- @aspects << before( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
19
+ @aspects << DSLClass.advise(:before, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
20
+ @aspects << DSLClass.before( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
17
21
  @aspects[1].should == @aspects[0]
18
22
  end
19
23
  end
20
24
 
21
- describe Object, "#after" do
25
+ describe "DSL method #after" do
22
26
  before :each do
23
27
  @advice = proc {|jp,*args| "advice"}
24
28
  @aspects = []
@@ -28,14 +32,15 @@ describe Object, "#after" do
28
32
  end
29
33
 
30
34
  it "should be equivalent to advise :after." do
31
- @aspects << advise(:after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
32
- @aspects << after( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
35
+ @aspects << DSLClass.advise(:after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
36
+ @aspects << DSLClass.after( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
33
37
  @aspects[1].should == @aspects[0]
34
38
  end
35
39
  end
36
40
 
37
- describe Object, "#after_raising_within_or_returning_from" do
41
+ describe "DSL method #after_raising_within_or_returning_from" do
38
42
  before :each do
43
+ @dsl = DSLClass.new
39
44
  @advice = proc {|jp,*args| "advice"}
40
45
  @aspects = []
41
46
  end
@@ -44,14 +49,15 @@ describe Object, "#after_raising_within_or_returning_from" do
44
49
  end
45
50
 
46
51
  it "should be equivalent to advise :after." do
47
- @aspects << after( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
48
- @aspects << after_raising_within_or_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
52
+ @aspects << DSLClass.after( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
53
+ @aspects << DSLClass.after_raising_within_or_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
49
54
  @aspects[1].should == @aspects[0]
50
55
  end
51
56
  end
52
57
 
53
- describe Object, "#after_returning" do
58
+ describe "DSL method #after_returning" do
54
59
  before :each do
60
+ @dsl = DSLClass.new
55
61
  @advice = proc {|jp,*args| "advice"}
56
62
  @aspects = []
57
63
  end
@@ -60,14 +66,15 @@ describe Object, "#after_returning" do
60
66
  end
61
67
 
62
68
  it "should be equivalent to advise :after_returning." do
63
- @aspects << advise(:after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
64
- @aspects << after_returning( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
69
+ @aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
70
+ @aspects << DSLClass.after_returning( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
65
71
  @aspects[1].should == @aspects[0]
66
72
  end
67
73
  end
68
74
 
69
- describe Object, "#after_returning_from" do
75
+ describe "DSL method #after_returning_from" do
70
76
  before :each do
77
+ @dsl = DSLClass.new
71
78
  @advice = proc {|jp,*args| "advice"}
72
79
  @aspects = []
73
80
  end
@@ -76,14 +83,15 @@ describe Object, "#after_returning_from" do
76
83
  end
77
84
 
78
85
  it "should be equivalent to advise :after_returning." do
79
- @aspects << advise(:after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
80
- @aspects << after_returning_from( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
86
+ @aspects << DSLClass.advise(:after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
87
+ @aspects << DSLClass.after_returning_from( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
81
88
  @aspects[1].should == @aspects[0]
82
89
  end
83
90
  end
84
91
 
85
- describe Object, "#after_raising" do
92
+ describe "DSL method #after_raising" do
86
93
  before :each do
94
+ @dsl = DSLClass.new
87
95
  @advice = proc {|jp,*args| "advice"}
88
96
  @aspects = []
89
97
  end
@@ -95,14 +103,15 @@ describe Object, "#after_raising" do
95
103
  class ThrowsUp
96
104
  def tosses_cookies *args; raise Exception.new(args.inspect); end
97
105
  end
98
- @aspects << advise(:after_raising, :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
99
- @aspects << after_raising( :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
106
+ @aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
107
+ @aspects << DSLClass.after_raising( :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
100
108
  @aspects[1].should == @aspects[0]
101
109
  end
102
110
  end
103
111
 
104
- describe Object, "#after_raising_within" do
112
+ describe "DSL method #after_raising_within" do
105
113
  before :each do
114
+ @dsl = DSLClass.new
106
115
  @advice = proc {|jp,*args| "advice"}
107
116
  @aspects = []
108
117
  end
@@ -114,14 +123,15 @@ describe Object, "#after_raising_within" do
114
123
  class ThrowsUp
115
124
  def tosses_cookies *args; raise Exception.new(args.inspect); end
116
125
  end
117
- @aspects << advise(:after_raising, :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
118
- @aspects << after_raising_within( :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
126
+ @aspects << DSLClass.advise(:after_raising, :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
127
+ @aspects << DSLClass.after_raising_within( :noop, :pointcut => {:type => ThrowsUp, :methods => :tosses_cookies}, &@advice)
119
128
  @aspects[1].should == @aspects[0]
120
129
  end
121
130
  end
122
131
 
123
- describe Object, "#before_and_after" do
132
+ describe "DSL method #before_and_after" do
124
133
  before :each do
134
+ @dsl = DSLClass.new
125
135
  @advice = proc {|jp,*args| "advice"}
126
136
  @aspects = []
127
137
  end
@@ -130,14 +140,15 @@ describe Object, "#before_and_after" do
130
140
  end
131
141
 
132
142
  it "should be equivalent to advise :before, :after." do
133
- @aspects << advise(:before, :after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
134
- @aspects << before_and_after(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
143
+ @aspects << DSLClass.advise(:before, :after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
144
+ @aspects << DSLClass.before_and_after(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
135
145
  @aspects[1].should == @aspects[0]
136
146
  end
137
147
  end
138
148
 
139
- describe Object, "#before_and_after_raising_within_or_returning_from" do
149
+ describe "DSL method #before_and_after_raising_within_or_returning_from" do
140
150
  before :each do
151
+ @dsl = DSLClass.new
141
152
  @advice = proc {|jp,*args| "advice"}
142
153
  @aspects = []
143
154
  end
@@ -146,14 +157,15 @@ describe Object, "#before_and_after_raising_within_or_returning_from" do
146
157
  end
147
158
 
148
159
  it "should be equivalent to advise :before and advise :after." do
149
- @aspects << advise(:before, :after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
150
- @aspects << before_and_after_raising_within_or_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
160
+ @aspects << DSLClass.advise(:before, :after, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
161
+ @aspects << DSLClass.before_and_after_raising_within_or_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
151
162
  @aspects[1].should == @aspects[0]
152
163
  end
153
164
  end
154
165
 
155
- describe Object, "#before_and_after_returning" do
166
+ describe "DSL method #before_and_after_returning" do
156
167
  before :each do
168
+ @dsl = DSLClass.new
157
169
  @advice = proc {|jp,*args| "advice"}
158
170
  @aspects = []
159
171
  end
@@ -162,14 +174,15 @@ describe Object, "#before_and_after_returning" do
162
174
  end
163
175
 
164
176
  it "should be equivalent to advise :before and advise :after_returning." do
165
- @aspects << advise(:before, :after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
166
- @aspects << before_and_after_returning( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
177
+ @aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
178
+ @aspects << DSLClass.before_and_after_returning( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
167
179
  @aspects[1].should == @aspects[0]
168
180
  end
169
181
  end
170
182
 
171
- describe Object, "#before_and_after_returning_from" do
183
+ describe "DSL method #before_and_after_returning_from" do
172
184
  before :each do
185
+ @dsl = DSLClass.new
173
186
  @advice = proc {|jp,*args| "advice"}
174
187
  @aspects = []
175
188
  end
@@ -178,14 +191,15 @@ describe Object, "#before_and_after_returning_from" do
178
191
  end
179
192
 
180
193
  it "should be equivalent to advise :before and advise :after_returning." do
181
- @aspects << advise(:before, :after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
182
- @aspects << before_and_after_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
194
+ @aspects << DSLClass.advise(:before, :after_returning, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
195
+ @aspects << DSLClass.before_and_after_returning_from(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
183
196
  @aspects[1].should == @aspects[0]
184
197
  end
185
198
  end
186
199
 
187
- describe Object, "#before_and_after_raising" do
200
+ describe "DSL method #before_and_after_raising" do
188
201
  before :each do
202
+ @dsl = DSLClass.new
189
203
  @advice = proc {|jp,*args| "advice"}
190
204
  @aspects = []
191
205
  end
@@ -194,14 +208,15 @@ describe Object, "#before_and_after_raising" do
194
208
  end
195
209
 
196
210
  it "should be equivalent to advise :before and advise :after_raising." do
197
- @aspects << advise(:before, :after_raising, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
198
- @aspects << before_and_after_raising(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
211
+ @aspects << DSLClass.advise(:before, :after_raising, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
212
+ @aspects << DSLClass.before_and_after_raising(:noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
199
213
  @aspects[1].should == @aspects[0]
200
214
  end
201
215
  end
202
216
 
203
- describe Object, "#around" do
217
+ describe "DSL method #around" do
204
218
  before :each do
219
+ @dsl = DSLClass.new
205
220
  @advice = proc {|jp,*args| "advice"}
206
221
  @aspects = []
207
222
  end
@@ -210,15 +225,14 @@ describe Object, "#around" do
210
225
  end
211
226
 
212
227
  it "should be equivalent to advise :around." do
213
- @aspects << advise(:around, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
214
- @aspects << around( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
228
+ @aspects << DSLClass.advise(:around, :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
229
+ @aspects << DSLClass.around( :noop, :pointcut => {:type => Watchful, :methods => :public_watchful_method}, &@advice)
215
230
  @aspects[1].should == @aspects[0]
216
231
  end
217
232
  end
218
233
 
219
- describe Object, "#advise (inferred arguments)" do
234
+ describe "DSL method #advise, when determining the \"self\" to advise," do
220
235
  before :each do
221
- @watchful = Watchful.new
222
236
  @aspects = []
223
237
  end
224
238
  after :each do
@@ -226,46 +240,109 @@ describe Object, "#advise (inferred arguments)" do
226
240
  end
227
241
 
228
242
  it "should ignore the default object \"self\" when an :object is specified." do
229
- class Watchful
230
- @@watchful = Watchful.new
243
+ class Watchful1
244
+ include Aquarium::Aspects::DSL::AspectDSL
245
+ @@watchful = Watchful1.new
231
246
  @@aspect = after(:object => @@watchful, :method => :public_watchful_method) {|jp,*args|}
232
247
  def self.watchful; @@watchful; end
233
248
  def self.aspect; @@aspect; end
234
249
  end
235
- @aspects << after(:object => Watchful.watchful, :method => :public_watchful_method) {|jp,*args|}
236
- @aspects << Watchful.aspect
250
+ @aspects << DSLClass.after(:object => Watchful1.watchful, :method => :public_watchful_method) {|jp,*args|}
251
+ @aspects << Watchful1.aspect
237
252
  @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
238
253
  @aspects[1].pointcuts.should == @aspects[0].pointcuts
239
254
  end
240
255
 
241
256
  it "should ignore the default object \"self\" when a :type is specified." do
242
- class Watchful
243
- @@aspect = after(:type => Watchful, :method => :public_watchful_method) {|jp,*args|}
257
+ class Watchful2
258
+ include Aquarium::Aspects::DSL::AspectDSL
259
+ @@aspect = after(:type => Watchful2, :method => :public_watchful_method) {|jp,*args|}
244
260
  def self.aspect; @@aspect; end
245
261
  end
246
- @aspects << after(:type => Watchful, :method => :public_watchful_method) {|jp,*args|}
247
- @aspects << Watchful.aspect
262
+ @aspects << DSLClass.after(:type => Watchful2, :method => :public_watchful_method) {|jp,*args|}
263
+ @aspects << Watchful2.aspect
248
264
  @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
249
265
  @aspects[1].pointcuts.should == @aspects[0].pointcuts
250
266
  end
267
+ end
268
+
269
+ describe "DSL method #advise, when determining the type or object to advise," do
270
+ before :each do
271
+ @aspects = []
272
+ end
273
+ after :each do
274
+ @aspects.each {|a| a.unadvise}
275
+ end
276
+
277
+ class WatchfulSelf
278
+ include Aquarium::Aspects::DSL::AspectDSL
279
+ @@aspect = nil
280
+ def self.aspect; @@aspect; end
281
+ def public_watchful_method; "public_watchful_method"; end
282
+ end
251
283
 
252
- it "should infer the type to advise as \"self\" when no :object, :type, or :pointcut is specified." do
253
- @aspects << after(:type => Watchful, :method => :public_watchful_method) {|jp,*args|}
254
- class Watchful
284
+ it "should infer the type as \"self\" when no :object, :type, or :pointcut is specified." do
285
+ @aspects << DSLClass.after(:type => WatchfulSelf, :method => :public_watchful_method) {|jp,*args|}
286
+ class WatchfulSelf
255
287
  @@aspect = after(:method => :public_watchful_method) {|jp,*args|}
256
- def self.aspect; @@aspect; end
257
288
  end
258
- @aspects << Watchful.aspect
289
+ @aspects << WatchfulSelf.aspect
290
+ @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
291
+ @aspects[1].pointcuts.should == @aspects[0].pointcuts
292
+ end
293
+
294
+ it "should infer the object as \"self\" when no :object, :type, or :pointcut is specified." do
295
+ watchful_self = WatchfulSelf.new
296
+ watchful_self.extend Aquarium::Aspects::DSL::AspectDSL
297
+ @aspects << watchful_self.after(:method => :public_watchful_method) {|jp,*args|}
298
+ @aspects << DSLClass.advise( :after, :pointcut => {:object => watchful_self, :method => :public_watchful_method}) {|jp,*args|}
259
299
  @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
260
300
  @aspects[1].pointcuts.should == @aspects[0].pointcuts
261
301
  end
262
302
 
303
+ it "should infer no types or objects if a :pointcut => {...} parameter is used and it does not specify a type or object." do
304
+ @aspects << DSLClass.after(:pointcut => {:method => /method/}) {|jp,*args|}
305
+ @aspects[0].join_points_matched.size.should == 0
306
+ end
307
+ end
308
+
309
+ describe "DSL method #advise, when parsing the parameter list," do
310
+ class Watchful3
311
+ include Aquarium::Aspects::DSL::AspectDSL
312
+ def public_watchful_method; "public_watchful_method"; end
313
+ end
314
+
315
+ before :each do
316
+ @aspects = []
317
+ end
318
+ after :each do
319
+ @aspects.each {|a| a.unadvise}
320
+ end
321
+
322
+ it "should infer the first symbol parameter after the advice kind parameter to be the method name to advise if no other :method => ... parameter is used." do
323
+ @aspects << Watchful3.after(:public_watchful_method) {|jp,*args|}
324
+ @aspects.each do |aspect|
325
+ aspect.join_points_matched.size.should == 1
326
+ aspect.specification[:methods].should == Set.new([:public_watchful_method])
327
+ end
328
+ end
329
+ end
330
+
331
+ describe "DSL method #advise, when determining instance or class methods to advise," do
332
+ before :each do
333
+ @aspects = []
334
+ end
335
+ after :each do
336
+ @aspects.each {|a| a.unadvise}
337
+ end
338
+
263
339
  it "should treat \"ClassName.advise\" as advising instance methods, by default." do
264
340
  class WatchfulExampleWithSeparateAdviseCall
341
+ include Aquarium::Aspects::DSL::AspectDSL
265
342
  def public_watchful_method *args; end
266
343
  end
267
344
  advice_called = 0
268
- WatchfulExampleWithSeparateAdviseCall.before :public_watchful_method do |jp, *args|
345
+ WatchfulExampleWithSeparateAdviseCall.advise :before, :public_watchful_method do |jp, *args|
269
346
  advice_called += 1
270
347
  end
271
348
  WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a1, :a2
@@ -275,11 +352,12 @@ describe Object, "#advise (inferred arguments)" do
275
352
 
276
353
  it "should treat \"ClassName.advise\" as advising instance methods when the :instance method option is specified." do
277
354
  class WatchfulExampleWithSeparateAdviseCall2
355
+ include Aquarium::Aspects::DSL::AspectDSL
278
356
  def self.class_public_watchful_method *args; end
279
357
  def public_watchful_method *args; end
280
358
  end
281
359
  advice_called = 0
282
- Aquarium::Aspects::Aspect.new :before, :type => WatchfulExampleWithSeparateAdviseCall2, :methods => /public_watchful_method/, :method_options =>[:instance] do |jp, *args|
360
+ WatchfulExampleWithSeparateAdviseCall2.advise :before, :type => WatchfulExampleWithSeparateAdviseCall2, :methods => /public_watchful_method/, :method_options =>[:instance] do |jp, *args|
283
361
  advice_called += 1
284
362
  end
285
363
  WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a1, :a2
@@ -291,24 +369,26 @@ describe Object, "#advise (inferred arguments)" do
291
369
  end
292
370
 
293
371
  it "should treat \"ClassName.advise\" as advising class methods when the :class method option is specified." do
294
- class WatchfulExampleWithSeparateAdviseCall
372
+ class WatchfulExampleWithSeparateAdviseCall3
373
+ include Aquarium::Aspects::DSL::AspectDSL
295
374
  def self.class_public_watchful_method *args; end
296
375
  def public_watchful_method *args; end
297
376
  end
298
377
  advice_called = 0
299
- WatchfulExampleWithSeparateAdviseCall.before :methods => /public_watchful_method/, :method_options =>[:class] do |jp, *args|
378
+ WatchfulExampleWithSeparateAdviseCall3.advise :before, :methods => /public_watchful_method/, :method_options =>[:class] do |jp, *args|
300
379
  advice_called += 1
301
380
  end
302
- WatchfulExampleWithSeparateAdviseCall.class_public_watchful_method :a1, :a2
303
- WatchfulExampleWithSeparateAdviseCall.class_public_watchful_method :a3, :a4
381
+ WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a1, :a2
382
+ WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a3, :a4
304
383
  advice_called.should == 2
305
- WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a1, :a2
306
- WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a3, :a4
384
+ WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a1, :a2
385
+ WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a3, :a4
307
386
  advice_called.should == 2
308
387
  end
309
388
 
310
389
  it "should invoke the type-based advise for all objects when the aspect is defined by calling #advise within the class definition." do
311
390
  class WatchfulExampleWithBeforeAdvice
391
+ include Aquarium::Aspects::DSL::AspectDSL
312
392
  @@advice_called = 0
313
393
  def public_watchful_method *args; end
314
394
  before :public_watchful_method do |jp, *args|
@@ -320,32 +400,16 @@ describe Object, "#advise (inferred arguments)" do
320
400
  WatchfulExampleWithBeforeAdvice.new.public_watchful_method :a3, :a4
321
401
  WatchfulExampleWithBeforeAdvice.advice_called.should == 2
322
402
  end
403
+ end
323
404
 
324
- it "should infer the object to advise as \"self\" when no :object, :type, or :pointcut is specified." do
325
- @aspects << @watchful.after(:method => :public_watchful_method) {|jp,*args|}
326
- @aspects << advise( :after, :pointcut => {:object => @watchful, :method => :public_watchful_method}) {|jp,*args|}
327
- @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
328
- @aspects[1].pointcuts.should == @aspects[0].pointcuts
329
- end
330
-
331
- it "should infer no types or objects if a :pointcut => {...} parameter is used and it does not specify a type or object." do
332
- @aspects << after(:pointcut => {:method => /method/}) {|jp,*args|}
333
- @aspects[0].join_points_matched.size.should == 0
334
- end
335
-
336
- it "should infer the first symbol parameter after the advice kind parameter is the method name to advise if no other :method => ... parameter is used." do
337
- @aspects << @watchful.after( :public_watchful_method) {|jp,*args|}
338
- @aspects.each do |aspect|
339
- aspect.join_points_matched.size.should == 1
340
- aspect.specification[:methods].should == Set.new([:public_watchful_method])
341
- end
405
+ describe "DSL methods for the advice kind, when determining instance or class methods to advise," do
406
+ class Watchful4
407
+ include Aquarium::Aspects::DSL::AspectDSL
408
+ def public_watchful_method; "public_watchful_method"; end
342
409
  end
343
- end
344
410
 
345
- describe Object, "advice kind convenience methods (inferred arguments)" do
346
411
  before :each do
347
412
  @advice = proc {|jp,*args| "advice"}
348
- @watchful = Watchful.new
349
413
  @aspects = []
350
414
  end
351
415
  after :each do
@@ -354,7 +418,7 @@ describe Object, "advice kind convenience methods (inferred arguments)" do
354
418
 
355
419
  (Aquarium::Aspects::Advice.kinds + [:after_raising_within_or_returning_from]).each do |advice_kind|
356
420
  it "##{advice_kind} method should infer the first symbol parameter as the method name to advise if no other :method => ... parameter is used." do
357
- @aspects << @watchful.method(advice_kind).call(:public_watchful_method, &@advice)
421
+ @aspects << Watchful4.method(advice_kind).call(:public_watchful_method, &@advice)
358
422
  @aspects.each do |aspect|
359
423
  aspect.join_points_matched.size.should == 1
360
424
  aspect.specification[:methods].should == Set.new([:public_watchful_method])
@@ -366,24 +430,24 @@ end
366
430
  describe "Synonyms for :types" do
367
431
  before :each do
368
432
  @advice = proc {|jp,*args| "advice"}
369
- @aspects = [after(:noop, :types => Watchful, :methods => :public_watchful_method, &@advice)]
433
+ @aspects = [DSLClass.after(:noop, :types => Watchful, :methods => :public_watchful_method, &@advice)]
370
434
  end
371
435
  after :each do
372
436
  @aspects.each {|a| a.unadvise}
373
437
  end
374
438
 
375
439
  it ":type is a synonym for :types" do
376
- @aspects << after(:noop, :type => Watchful, :methods => :public_watchful_method, &@advice)
440
+ @aspects << DSLClass.after(:noop, :type => Watchful, :methods => :public_watchful_method, &@advice)
377
441
  @aspects[1].should == @aspects[0]
378
442
  end
379
443
 
380
444
  it ":within_types is a synonym for :types" do
381
- @aspects << after(:noop, :within_type => Watchful, :methods => :public_watchful_method, &@advice)
445
+ @aspects << DSLClass.after(:noop, :within_type => Watchful, :methods => :public_watchful_method, &@advice)
382
446
  @aspects[1].should == @aspects[0]
383
447
  end
384
448
 
385
449
  it ":within_types is a synonym for :types" do
386
- @aspects << after(:noop, :within_types => Watchful, :methods => :public_watchful_method, &@advice)
450
+ @aspects << DSLClass.after(:noop, :within_types => Watchful, :methods => :public_watchful_method, &@advice)
387
451
  @aspects[1].should == @aspects[0]
388
452
  end
389
453
  end
@@ -391,25 +455,24 @@ end
391
455
  describe "Synonyms for :objects" do
392
456
  before :each do
393
457
  @advice = proc {|jp,*args| "advice"}
394
- @watchful = Watchful.new
395
- @aspects = [after(:noop, :objects => @watchful, :methods => :public_watchful_method, &@advice)]
458
+ @aspects = [DSLClass.after(:noop, :objects => @watchful, :methods => :public_watchful_method, &@advice)]
396
459
  end
397
460
  after :each do
398
461
  @aspects.each {|a| a.unadvise}
399
462
  end
400
463
 
401
464
  it ":object is a synonym for :objects" do
402
- @aspects << after(:noop, :object => @watchful, :methods => :public_watchful_method, &@advice)
465
+ @aspects << DSLClass.after(:noop, :object => @watchful, :methods => :public_watchful_method, &@advice)
403
466
  @aspects[1].should == @aspects[0]
404
467
  end
405
468
 
406
469
  it ":within_objects is a synonym for :objects" do
407
- @aspects << after(:noop, :within_object => @watchful, :methods => :public_watchful_method, &@advice)
470
+ @aspects << DSLClass.after(:noop, :within_object => @watchful, :methods => :public_watchful_method, &@advice)
408
471
  @aspects[1].should == @aspects[0]
409
472
  end
410
473
 
411
474
  it ":within_objects is a synonym for :objects" do
412
- @aspects << after(:noop, :within_objects => @watchful, :methods => :public_watchful_method, &@advice)
475
+ @aspects << DSLClass.after(:noop, :within_objects => @watchful, :methods => :public_watchful_method, &@advice)
413
476
  @aspects[1].should == @aspects[0]
414
477
  end
415
478
  end
@@ -417,25 +480,24 @@ end
417
480
  describe "Synonyms for :methods" do
418
481
  before :each do
419
482
  @advice = proc {|jp,*args| "advice"}
420
- @watchful = Watchful.new
421
- @aspects = [after(:noop, :objects => @watchful, :methods => :public_watchful_method, &@advice)]
483
+ @aspects = [DSLClass.after(:noop, :objects => @watchful, :methods => :public_watchful_method, &@advice)]
422
484
  end
423
485
  after :each do
424
486
  @aspects.each {|a| a.unadvise}
425
487
  end
426
488
 
427
489
  it ":method is a synonym for :methods" do
428
- @aspects << after(:noop, :object => @watchful, :method => :public_watchful_method, &@advice)
490
+ @aspects << DSLClass.after(:noop, :object => @watchful, :method => :public_watchful_method, &@advice)
429
491
  @aspects[1].should == @aspects[0]
430
492
  end
431
493
 
432
494
  it ":within_methods is a synonym for :methods" do
433
- @aspects << after(:noop, :within_object => @watchful, :within_methods => :public_watchful_method, &@advice)
495
+ @aspects << DSLClass.after(:noop, :within_object => @watchful, :within_methods => :public_watchful_method, &@advice)
434
496
  @aspects[1].should == @aspects[0]
435
497
  end
436
498
 
437
499
  it ":within_methods is a synonym for :methods" do
438
- @aspects << after(:noop, :within_objects => @watchful, :within_method => :public_watchful_method, &@advice)
500
+ @aspects << DSLClass.after(:noop, :within_objects => @watchful, :within_method => :public_watchful_method, &@advice)
439
501
  @aspects[1].should == @aspects[0]
440
502
  end
441
503
  end
@@ -443,32 +505,32 @@ end
443
505
  describe "Synonyms for :pointcut" do
444
506
  before :each do
445
507
  @advice = proc {|jp,*args| "advice"}
446
- @watchful = Watchful.new
447
- @aspects = [after(:noop, :pointcut => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)]
508
+ @aspects = [DSLClass.after(:noop, :pointcut => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)]
448
509
  end
449
510
  after :each do
450
511
  @aspects.each {|a| a.unadvise}
451
512
  end
452
513
 
453
514
  it ":pointcuts is a synonym for :pointcut" do
454
- @aspects << after(:noop, :pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
515
+ @aspects << DSLClass.after(:noop, :pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
455
516
  @aspects[1].should == @aspects[0]
456
517
  end
457
518
 
458
519
  it "should accept :within_pointcuts as a synonym for :pointcut." do
459
- @aspects << after(:noop, :within_pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
520
+ @aspects << DSLClass.after(:noop, :within_pointcuts => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
460
521
  @aspects[1].should == @aspects[0]
461
522
  end
462
523
 
463
524
  it "should accept :within_pointcut as a synonym for :pointcut." do
464
- @aspects << after(:noop, :within_pointcut => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
525
+ @aspects << DSLClass.after(:noop, :within_pointcut => {:objects => @watchful, :methods => :public_watchful_method}, &@advice)
465
526
  @aspects[1].should == @aspects[0]
466
527
  end
467
528
  end
468
529
 
469
- describe Object, "#advise (or synonyms) called within a type body" do
530
+ describe "DSL method #advise (or synonyms) called within a type body" do
470
531
  it "will not advise a method whose definition hasn't been seen yet in the type body." do
471
532
  class WatchfulWithMethodAlreadyDefined
533
+ include Aquarium::Aspects::DSL::AspectDSL
472
534
  @@advice_called = 0
473
535
  def public_watchful_method *args; end
474
536
  before :public_watchful_method do |jp, *args|
@@ -480,6 +542,7 @@ describe Object, "#advise (or synonyms) called within a type body" do
480
542
  WatchfulWithMethodAlreadyDefined.new.public_watchful_method :a3, :a4
481
543
  WatchfulWithMethodAlreadyDefined.advice_called.should == 2
482
544
  class WatchfulWithMethodNotYetDefined
545
+ include Aquarium::Aspects::DSL::AspectDSL
483
546
  @@advice_called = 0
484
547
  before(:public_watchful_method) {|jp, *args| @@advice_called += 1}
485
548
  def public_watchful_method *args; end
@@ -491,24 +554,25 @@ describe Object, "#advise (or synonyms) called within a type body" do
491
554
  end
492
555
  end
493
556
 
494
- describe Object, "#pointcut" do
557
+ describe "DSL method #pointcut" do
495
558
  class PC1;
496
559
  def doit; end
497
560
  end
498
561
 
499
562
  it "should match equivalent join points as Pointcut.new" do
500
- pointcut1 = pointcut :type => PC1, :method => :doit
563
+ pointcut1 = DSLClass.pointcut :type => PC1, :method => :doit
501
564
  pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC1, :method => :doit
502
565
  pointcut1.join_points_matched.should == pointcut2.join_points_matched
503
566
  pointcut1.join_points_not_matched.should == pointcut2.join_points_not_matched
504
567
  end
505
568
 
506
569
  it "should use self as the object if no object or type is specified." do
507
- class PC1
570
+ class PC2
571
+ include Aquarium::Aspects::DSL::AspectDSL
508
572
  POINTCUT = pointcut :method => :doit
509
573
  end
510
- pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC1, :method => :doit
511
- PC1::POINTCUT.join_points_matched.should == pointcut2.join_points_matched
512
- PC1::POINTCUT.join_points_not_matched.should == pointcut2.join_points_not_matched
574
+ pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC2, :method => :doit
575
+ PC2::POINTCUT.join_points_matched.should == pointcut2.join_points_matched
576
+ PC2::POINTCUT.join_points_not_matched.should == pointcut2.join_points_not_matched
513
577
  end
514
578
  end