aquarium 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # Example demonstrating "around" advice that traces calls to all methods in
3
- # classes Foo and Bar
2
+ # Example demonstrating "around" advice that traces calls to all
3
+ # methods in classes Foo and Bar.
4
4
 
5
5
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
6
6
  require 'aquarium'
@@ -38,13 +38,16 @@ bar1.do_something_else :b3, :b4
38
38
 
39
39
  include Aquarium::Aspects
40
40
 
41
- Aspect.new :around, :calls_to => :all_methods, :for_types => [Aquarium::Foo, Aquarium::Bar],
42
- :method_options => :exclude_ancestor_methods do |execution_point, obj, *args|
41
+ # "jp" is the "join point", a.k.a. the current execution point.
42
+ Aspect.new :around, :calls_to => :all_methods,
43
+ :for_types => [Aquarium::Foo, Aquarium::Bar],
44
+ :method_options => :exclude_ancestor_methods do |jp, obj, *args|
43
45
  begin
44
- p "Entering: #{execution_point.target_type.name}##{execution_point.method_name}: args = #{args.inspect}"
45
- execution_point.proceed
46
+ names = "#{jp.target_type.name}##{jp.method_name}"
47
+ p "Entering: #{names}: args = #{args.inspect}"
48
+ jp.proceed
46
49
  ensure
47
- p "Leaving: #{execution_point.target_type.name}##{execution_point.method_name}: args = #{args.inspect}"
50
+ p "Leaving: #{names}: args = #{args.inspect}"
48
51
  end
49
52
  end
50
53
 
@@ -55,15 +58,17 @@ foo2.do_it :b5, :b6
55
58
  bar1 = Aquarium::Bar.new :a7, :a8
56
59
  bar1.do_something_else :b7, :b8
57
60
 
58
- # The "begin/ensure/end" idiom shown causes the advice to return the correct value; the result
59
- # of the "proceed", rather than the value returned by "p"!
60
- Aspect.new :around, :invocations_of => :initialize, :for_types => [Aquarium::Foo, Aquarium::Bar],
61
- :restricting_methods_to => :private_methods do |execution_point, obj, *args|
61
+ # The "begin/ensure/end" idiom shown causes the advice to return the correct
62
+ # value; the result of the "proceed", rather than the value returned by "p"!
63
+ Aspect.new :around, :invocations_of => :initialize,
64
+ :for_types => [Aquarium::Foo, Aquarium::Bar],
65
+ :restricting_methods_to => :private_methods do |jp, obj, *args|
62
66
  begin
63
- p "Entering: #{execution_point.target_type.name}##{execution_point.method_name}: args = #{args.inspect}"
64
- execution_point.proceed
67
+ names = "#{jp.target_type.name}##{jp.method_name}"
68
+ p "Entering: #{names}: args = #{args.inspect}"
69
+ jp.proceed
65
70
  ensure
66
- p "Leaving: #{execution_point.target_type.name}##{execution_point.method_name}: args = #{args.inspect}"
71
+ p "Leaving: #{names}: args = #{args.inspect}"
67
72
  end
68
73
  end
69
74
 
@@ -72,5 +77,4 @@ foo2 = Aquarium::Foo.new :a9, :a10
72
77
  foo2.do_it :b9, :b10
73
78
 
74
79
  bar1 = Aquarium::Bar.new :a11, :a12
75
- bar1.do_something_else :b11, :b12
76
-
80
+ bar1.do_something_else :b11, :b12
@@ -17,11 +17,13 @@ module Aquarium
17
17
  module Reusables
18
18
  module TraceMethods
19
19
  def self.append_features mod
20
- Aquarium::Aspects::Aspect.new :around,
21
- :type => mod, :methods => :all, :method_options => [:exclude_ancestor_methods] do |jp, object, *args|
22
- p "Entering: "+jp.target_type.name+"#"+jp.method_name.to_s+": args = "+args.inspect
20
+ Aquarium::Aspects::Aspect.new :around, :type => mod,
21
+ :methods => :all,
22
+ :method_options => [:exclude_ancestor_methods] do |jp, object, *args|
23
+ names = "#{jp.target_type.name}##{jp.method_name}"
24
+ p "Entering: #{names}: args = #{args.inspect}"
23
25
  jp.proceed
24
- p "Leaving: "+jp.target_type.name+"#"+jp.method_name.to_s+": args = "+args.inspect
26
+ p "Leaving: #{names}: args = #{args.inspect}"
25
27
  end
26
28
  end
27
29
  end
@@ -32,7 +34,8 @@ class NotTraced1
32
34
  def doit; p "NotTraced1#doit"; end
33
35
  end
34
36
  p "You will be warned that no join points in NotTraced2 were matched."
35
- p "This happens because the include statement and hence the aspect evaluation happen BEFORE any methods are defined!"
37
+ p "This happens because the include statement and hence the aspect evaluation"
38
+ p " happen BEFORE any methods are defined!"
36
39
  class NotTraced2
37
40
  include Aquarium::Reusables::TraceMethods
38
41
  def doit; p "NotTraced2#doit"; end
@@ -42,9 +42,9 @@ module Aquarium
42
42
  unless @specification[:exclude_types_calculated].nil?
43
43
  return true if @specification[:exclude_types_calculated].find do |t|
44
44
  case t
45
- when String: type_or_object.name.eql?(t)
46
- when Symbol: type_or_object.name.eql?(t.to_s)
47
- when Regexp: type_or_object.name =~ t
45
+ when String then type_or_object.name.eql?(t)
46
+ when Symbol then type_or_object.name.eql?(t.to_s)
47
+ when Regexp then type_or_object.name =~ t
48
48
  else type_or_object == t
49
49
  end
50
50
  end
@@ -9,7 +9,7 @@ module Aquarium
9
9
  unless defined? MAJOR
10
10
  MAJOR = 0
11
11
  MINOR = 4
12
- TINY = 3
12
+ TINY = 4
13
13
  RELEASE_CANDIDATE = nil
14
14
 
15
15
  # RANDOM_TOKEN: 0.598704893979657
@@ -3,5 +3,5 @@ require 'spec/rake/verify_rcov'
3
3
 
4
4
  RCov::VerifyTask.new(:verify_rcov => :spec) do |t|
5
5
  t.threshold = 100.0 # Make sure you have rcov 0.7 or higher!
6
- t.index_html = '../doc/output/coverage/index.html'
6
+ t.index_html = '../doc/aquarium/out/coverage/index.html'
7
7
  end
@@ -116,84 +116,84 @@ describe "concurrent advice", :shared => true do
116
116
  end
117
117
 
118
118
  describe "Using two :before advices" do
119
- setup do
119
+ before :each do
120
120
  @advice_kinds = [:before, :before]
121
121
  end
122
122
  it_should_behave_like "concurrent advice"
123
123
  end
124
124
 
125
125
  describe "Using two :after advices" do
126
- setup do
126
+ before :each do
127
127
  @advice_kinds = [:after, :after]
128
128
  end
129
129
  it_should_behave_like "concurrent advice"
130
130
  end
131
131
 
132
132
  describe "Using two :after_returning advices" do
133
- setup do
133
+ before :each do
134
134
  @advice_kinds = [:after_returning, :after_returning]
135
135
  end
136
136
  it_should_behave_like "concurrent advice"
137
137
  end
138
138
 
139
139
  describe "Using two :after_raising advices" do
140
- setup do
140
+ before :each do
141
141
  @advice_kinds = [:after_raising, :after_raising]
142
142
  end
143
143
  it_should_behave_like "concurrent advice"
144
144
  end
145
145
 
146
146
  describe "Using two :around advices" do
147
- setup do
147
+ before :each do
148
148
  @advice_kinds = [:around, :around]
149
149
  end
150
150
  it_should_behave_like "concurrent advice"
151
151
  end
152
152
 
153
153
  describe "Using :before advice and :after advice" do
154
- setup do
154
+ before :each do
155
155
  @advice_kinds = [:before, :after]
156
156
  end
157
157
  it_should_behave_like "concurrent advice"
158
158
  end
159
159
 
160
160
  describe "Using :before advice and :after_returning advice" do
161
- setup do
161
+ before :each do
162
162
  @advice_kinds = [:before, :after_returning]
163
163
  end
164
164
  it_should_behave_like "concurrent advice"
165
165
  end
166
166
 
167
167
  describe "Using :before advice and :after_raising advice" do
168
- setup do
168
+ before :each do
169
169
  @advice_kinds = [:before, :after_raising]
170
170
  end
171
171
  it_should_behave_like "concurrent advice"
172
172
  end
173
173
 
174
174
  describe "Using :before advice and :around advice" do
175
- setup do
175
+ before :each do
176
176
  @advice_kinds = [:before, :around]
177
177
  end
178
178
  it_should_behave_like "concurrent advice"
179
179
  end
180
180
 
181
181
  describe "Using :after advice and :after_returning advice" do
182
- setup do
182
+ before :each do
183
183
  @advice_kinds = [:after, :after_returning]
184
184
  end
185
185
  it_should_behave_like "concurrent advice"
186
186
  end
187
187
 
188
188
  describe "Using :after advice and :after_raising advice" do
189
- setup do
189
+ before :each do
190
190
  @advice_kinds = [:after, :after_raising]
191
191
  end
192
192
  it_should_behave_like "concurrent advice"
193
193
  end
194
194
 
195
195
  describe "Using :after advice and :around advice" do
196
- setup do
196
+ before :each do
197
197
  @advice_kinds = [:after, :around]
198
198
  end
199
199
  it_should_behave_like "concurrent advice"
@@ -201,70 +201,70 @@ end
201
201
 
202
202
 
203
203
  describe "Using :after_returning advice and :after_raising advice" do
204
- setup do
204
+ before :each do
205
205
  @advice_kinds = [:after_returning, :after_raising]
206
206
  end
207
207
  it_should_behave_like "concurrent advice"
208
208
  end
209
209
 
210
210
  describe "Using :after_returning advice and :around advice" do
211
- setup do
211
+ before :each do
212
212
  @advice_kinds = [:after_returning, :around]
213
213
  end
214
214
  it_should_behave_like "concurrent advice"
215
215
  end
216
216
 
217
217
  describe "Using :after_raising advice and :around advice" do
218
- setup do
218
+ before :each do
219
219
  @advice_kinds = [:after_raising, :around]
220
220
  end
221
221
  it_should_behave_like "concurrent advice"
222
222
  end
223
223
 
224
224
  describe "Using three :before advices" do
225
- setup do
225
+ before :each do
226
226
  3.times {|i| @advice_kinds[i] = :before}
227
227
  end
228
228
  it_should_behave_like "concurrent advice"
229
229
  end
230
230
 
231
231
  describe "Using three :before advices" do
232
- setup do
232
+ before :each do
233
233
  3.times {|i| @advice_kinds[i] = :before}
234
234
  end
235
235
  it_should_behave_like "concurrent advice"
236
236
  end
237
237
 
238
238
  describe "Using three :after advices" do
239
- setup do
239
+ before :each do
240
240
  3.times {|i| @advice_kinds[i] = :after}
241
241
  end
242
242
  it_should_behave_like "concurrent advice"
243
243
  end
244
244
 
245
245
  describe "Using three :after_returning advices" do
246
- setup do
246
+ before :each do
247
247
  3.times {|i| @advice_kinds[i] = :after_returning}
248
248
  end
249
249
  it_should_behave_like "concurrent advice"
250
250
  end
251
251
 
252
252
  describe "Using three :after_raising advices" do
253
- setup do
253
+ before :each do
254
254
  3.times {|i| @advice_kinds[i] = :after_raising}
255
255
  end
256
256
  it_should_behave_like "concurrent advice"
257
257
  end
258
258
 
259
259
  describe "Using three :around advices" do
260
- setup do
260
+ before :each do
261
261
  3.times {|i| @advice_kinds[i] = :around}
262
262
  end
263
263
  it_should_behave_like "concurrent advice"
264
264
  end
265
265
 
266
266
  describe "Using two :before advices and one :after advice" do
267
- setup do
267
+ before :each do
268
268
  2.times {|i| @advice_kinds[i] = :before}
269
269
  @advice_kinds[2] = :after
270
270
  end
@@ -272,7 +272,7 @@ describe "Using two :before advices and one :after advice" do
272
272
  end
273
273
 
274
274
  describe "Using two :before advices and one :after_returning advice" do
275
- setup do
275
+ before :each do
276
276
  2.times {|i| @advice_kinds[i] = :before}
277
277
  @advice_kinds[2] = :after_returning
278
278
  end
@@ -280,7 +280,7 @@ describe "Using two :before advices and one :after_returning advice" do
280
280
  end
281
281
 
282
282
  describe "Using two :before advices and one :after_raising advice" do
283
- setup do
283
+ before :each do
284
284
  2.times {|i| @advice_kinds[i] = :before}
285
285
  @advice_kinds[2] = :after_raising
286
286
  end
@@ -288,7 +288,7 @@ describe "Using two :before advices and one :after_raising advice" do
288
288
  end
289
289
 
290
290
  describe "Using two :before advices and one :around advice" do
291
- setup do
291
+ before :each do
292
292
  2.times {|i| @advice_kinds[i] = :before}
293
293
  @advice_kinds[2] = :around
294
294
  end
@@ -296,7 +296,7 @@ describe "Using two :before advices and one :around advice" do
296
296
  end
297
297
 
298
298
  describe "Using two :after advices and one :before advice" do
299
- setup do
299
+ before :each do
300
300
  2.times {|i| @advice_kinds[i] = :after}
301
301
  @advice_kinds[2] = :before
302
302
  end
@@ -304,7 +304,7 @@ describe "Using two :after advices and one :before advice" do
304
304
  end
305
305
 
306
306
  describe "Using two :after advices and one :after_returning advice" do
307
- setup do
307
+ before :each do
308
308
  2.times {|i| @advice_kinds[i] = :after}
309
309
  @advice_kinds[2] = :after_returning
310
310
  end
@@ -312,7 +312,7 @@ describe "Using two :after advices and one :after_returning advice" do
312
312
  end
313
313
 
314
314
  describe "Using two :after advices and one :after_raising advice" do
315
- setup do
315
+ before :each do
316
316
  2.times {|i| @advice_kinds[i] = :after}
317
317
  @advice_kinds[2] = :after_raising
318
318
  end
@@ -320,7 +320,7 @@ describe "Using two :after advices and one :after_raising advice" do
320
320
  end
321
321
 
322
322
  describe "Using two :after advices and one :around advice" do
323
- setup do
323
+ before :each do
324
324
  2.times {|i| @advice_kinds[i] = :after}
325
325
  @advice_kinds[2] = :around
326
326
  end
@@ -328,7 +328,7 @@ describe "Using two :after advices and one :around advice" do
328
328
  end
329
329
 
330
330
  describe "Using two :after_returning advices and one :before advice" do
331
- setup do
331
+ before :each do
332
332
  2.times {|i| @advice_kinds[i] = :after_returning}
333
333
  @advice_kinds[2] = :before
334
334
  end
@@ -336,7 +336,7 @@ describe "Using two :after_returning advices and one :before advice" do
336
336
  end
337
337
 
338
338
  describe "Using two :after_returning advices and one :after advice" do
339
- setup do
339
+ before :each do
340
340
  2.times {|i| @advice_kinds[i] = :after_returning}
341
341
  @advice_kinds[2] = :after
342
342
  end
@@ -344,7 +344,7 @@ describe "Using two :after_returning advices and one :after advice" do
344
344
  end
345
345
 
346
346
  describe "Using two :after_returning advices and one :after_raising advice" do
347
- setup do
347
+ before :each do
348
348
  2.times {|i| @advice_kinds[i] = :after_returning}
349
349
  @advice_kinds[2] = :after_raising
350
350
  end
@@ -352,7 +352,7 @@ describe "Using two :after_returning advices and one :after_raising advice" do
352
352
  end
353
353
 
354
354
  describe "Using two :after_returning advices and one :around advice" do
355
- setup do
355
+ before :each do
356
356
  2.times {|i| @advice_kinds[i] = :after_returning}
357
357
  @advice_kinds[2] = :around
358
358
  end
@@ -360,7 +360,7 @@ describe "Using two :after_returning advices and one :around advice" do
360
360
  end
361
361
 
362
362
  describe "Using two :after_raising advices and one :before advice" do
363
- setup do
363
+ before :each do
364
364
  2.times {|i| @advice_kinds[i] = :after_raising}
365
365
  @advice_kinds[2] = :before
366
366
  end
@@ -368,7 +368,7 @@ describe "Using two :after_raising advices and one :before advice" do
368
368
  end
369
369
 
370
370
  describe "Using two :after_raising advices and one :after advice" do
371
- setup do
371
+ before :each do
372
372
  2.times {|i| @advice_kinds[i] = :after_raising}
373
373
  @advice_kinds[2] = :after
374
374
  end
@@ -376,7 +376,7 @@ describe "Using two :after_raising advices and one :after advice" do
376
376
  end
377
377
 
378
378
  describe "Using two :after_raising advices and one :after_raising advice" do
379
- setup do
379
+ before :each do
380
380
  2.times {|i| @advice_kinds[i] = :after_raising}
381
381
  @advice_kinds[2] = :after_raising
382
382
  end
@@ -384,7 +384,7 @@ describe "Using two :after_raising advices and one :after_raising advice" do
384
384
  end
385
385
 
386
386
  describe "Using two :after_raising advices and one :around advice" do
387
- setup do
387
+ before :each do
388
388
  2.times {|i| @advice_kinds[i] = :after_raising}
389
389
  @advice_kinds[2] = :around
390
390
  end
@@ -392,7 +392,7 @@ describe "Using two :after_raising advices and one :around advice" do
392
392
  end
393
393
 
394
394
  describe "Using two :around advices and one :before advice" do
395
- setup do
395
+ before :each do
396
396
  2.times {|i| @advice_kinds[i] = :around}
397
397
  @advice_kinds[2] = :before
398
398
  end
@@ -400,7 +400,7 @@ describe "Using two :around advices and one :before advice" do
400
400
  end
401
401
 
402
402
  describe "Using two :around advices and one :after advice" do
403
- setup do
403
+ before :each do
404
404
  2.times {|i| @advice_kinds[i] = :around}
405
405
  @advice_kinds[2] = :after
406
406
  end
@@ -408,7 +408,7 @@ describe "Using two :around advices and one :after advice" do
408
408
  end
409
409
 
410
410
  describe "Using two :around advices and one :after_returning advice" do
411
- setup do
411
+ before :each do
412
412
  2.times {|i| @advice_kinds[i] = :around}
413
413
  @advice_kinds[2] = :after_returning
414
414
  end
@@ -416,7 +416,7 @@ describe "Using two :around advices and one :after_returning advice" do
416
416
  end
417
417
 
418
418
  describe "Using two :around advices and one :after_raising advice" do
419
- setup do
419
+ before :each do
420
420
  2.times {|i| @advice_kinds[i] = :around}
421
421
  @advice_kinds[2] = :after_raising
422
422
  end