aquarium 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Aquarium.ipr +253 -0
  2. data/Aquarium.iws +629 -0
  3. data/CHANGES +43 -0
  4. data/UPGRADE +13 -7
  5. data/examples/method_tracing_example_spec.rb +4 -1
  6. data/lib/aquarium/aspects/aspect.rb +28 -11
  7. data/lib/aquarium/aspects/exclusion_handler.rb +1 -1
  8. data/lib/aquarium/aspects/join_point.rb +58 -14
  9. data/lib/aquarium/aspects/pointcut.rb +5 -6
  10. data/lib/aquarium/extras/design_by_contract.rb +1 -1
  11. data/lib/aquarium/finders/method_finder.rb +1 -4
  12. data/lib/aquarium/finders/type_finder.rb +8 -1
  13. data/lib/aquarium/utils.rb +1 -0
  14. data/lib/aquarium/utils/default_logger.rb +20 -0
  15. data/lib/aquarium/utils/options_utils.rb +74 -12
  16. data/lib/aquarium/utils/type_utils.rb +1 -7
  17. data/lib/aquarium/version.rb +1 -1
  18. data/spec/aquarium/aspects/advice_chain_node_spec.rb +1 -1
  19. data/spec/aquarium/aspects/advice_spec.rb +1 -1
  20. data/spec/aquarium/aspects/aspect_invocation_spec.rb +1531 -1465
  21. data/spec/aquarium/aspects/aspect_spec.rb +22 -27
  22. data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +1 -1
  23. data/spec/aquarium/aspects/aspect_with_subtypes_spec.rb +1 -1
  24. data/spec/aquarium/aspects/concurrent_aspects_spec.rb +1 -1
  25. data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +1 -1
  26. data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +434 -424
  27. data/spec/aquarium/aspects/join_point_spec.rb +27 -4
  28. data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +98 -102
  29. data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +95 -107
  30. data/spec/aquarium/aspects/pointcut_spec.rb +1365 -1382
  31. data/spec/aquarium/extensions/hash_spec.rb +1 -1
  32. data/spec/aquarium/extensions/set_spec.rb +1 -1
  33. data/spec/aquarium/finders/finder_result_spec.rb +1 -1
  34. data/spec/aquarium/finders/method_finder_spec.rb +1 -1
  35. data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +63 -145
  36. data/spec/aquarium/{spec_example_classes.rb → spec_example_types.rb} +35 -0
  37. data/spec/aquarium/utils/default_logger_spec.rb +28 -0
  38. data/spec/aquarium/utils/hash_utils_spec.rb +1 -1
  39. data/spec/aquarium/utils/logic_error_spec.rb +1 -1
  40. data/spec/aquarium/utils/name_utils_spec.rb +1 -1
  41. data/spec/aquarium/utils/nil_object_spec.rb +1 -1
  42. data/spec/aquarium/utils/options_utils_spec.rb +122 -0
  43. data/spec/aquarium/utils/set_utils_spec.rb +1 -1
  44. metadata +9 -4
@@ -1,12 +1,13 @@
1
1
 
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
- require File.dirname(__FILE__) + '/../spec_example_classes'
3
+ require File.dirname(__FILE__) + '/../spec_example_types'
4
4
  require 'aquarium/aspects'
5
+ require 'logger'
5
6
 
6
7
  include Aquarium::Aspects
7
8
 
8
9
 
9
- describe "Aspects that specify the private implementation methods inserted by other aspects" do
10
+ describe Aspect, " cannot advise the private implementation methods inserted by other aspects" do
10
11
  it "should have no affect." do
11
12
  class WithAspectLikeMethod
12
13
  def _aspect_foo; end
@@ -17,7 +18,7 @@ describe "Aspects that specify the private implementation methods inserted by ot
17
18
  end
18
19
  end
19
20
 
20
- describe "When an aspect advises a type" do
21
+ describe Aspect, " when advising a type" do
21
22
  before(:all) do
22
23
  @advice = Proc.new {}
23
24
  end
@@ -38,7 +39,7 @@ describe "When an aspect advises a type" do
38
39
  end
39
40
  end
40
41
 
41
- describe "When an aspect advises an object" do
42
+ describe Aspect, " when advising an object" do
42
43
  before(:all) do
43
44
  @advice = Proc.new {}
44
45
  end
@@ -61,7 +62,7 @@ describe "When an aspect advises an object" do
61
62
  end
62
63
  end
63
64
 
64
- describe "Aspects with :before advice" do
65
+ describe Aspect, " with :before advice" do
65
66
  after(:each) do
66
67
  @aspect.unadvise if @aspect
67
68
  end
@@ -90,7 +91,7 @@ describe "Aspects with :before advice" do
90
91
  end
91
92
  end
92
93
 
93
- describe "Aspects with :after advice" do
94
+ describe Aspect, " with :after advice" do
94
95
  after(:each) do
95
96
  @aspect.unadvise if @aspect
96
97
  end
@@ -162,7 +163,7 @@ describe "Aspects with :after advice" do
162
163
  end
163
164
  end
164
165
 
165
- describe "Aspects with :after_returning advice" do
166
+ describe Aspect, " with :after_returning advice" do
166
167
  after(:each) do
167
168
  @aspect.unadvise if @aspect
168
169
  end
@@ -219,7 +220,7 @@ describe "Aspects with :after_returning advice" do
219
220
  end
220
221
  end
221
222
 
222
- describe "Aspects with :after_raising advice" do
223
+ describe Aspect, " with :after_raising advice" do
223
224
  after(:each) do
224
225
  @aspect.unadvise if @aspect
225
226
  end
@@ -288,7 +289,7 @@ describe "Aspects with :after_raising advice" do
288
289
  end
289
290
  end
290
291
 
291
- describe "Aspects with :before and :after advice" do
292
+ describe Aspect, " with :before and :after advice" do
292
293
  after(:each) do
293
294
  @aspect.unadvise if @aspect
294
295
  end
@@ -329,7 +330,7 @@ describe "Aspects with :before and :after advice" do
329
330
  end
330
331
  end
331
332
 
332
- describe "Aspects with :before and :after_returning advice" do
333
+ describe Aspect, " with :before and :after_returning advice" do
333
334
  after(:each) do
334
335
  @aspect.unadvise if @aspect
335
336
  end
@@ -363,7 +364,7 @@ describe "Aspects with :before and :after_returning advice" do
363
364
  end
364
365
  end
365
366
 
366
- describe "Aspects with :before and :after_raising advice" do
367
+ describe Aspect, " with :before and :after_raising advice" do
367
368
  after(:each) do
368
369
  @aspect.unadvise if @aspect
369
370
  end
@@ -397,7 +398,7 @@ describe "Aspects with :before and :after_raising advice" do
397
398
  end
398
399
  end
399
400
 
400
- describe "Aspects with :around advice" do
401
+ describe Aspect, " with :around advice" do
401
402
  after(:each) do
402
403
  @aspect.unadvise if @aspect
403
404
  end
@@ -624,7 +625,7 @@ describe Aspect, "#unadvise for 'empty' aspects" do
624
625
 
625
626
  it "should do nothing for unadvised types." do
626
627
  expected_methods = (Watchful.private_methods + Watchful.private_instance_methods).sort
627
- aspect = Aspect.new :around, :type => Watchful, :method => /does_not_exist/, :advice => @advice
628
+ aspect = Aspect.new :around, :type => Watchful, :method => /does_not_exist/, :advice => @advice, :severity => Logger::Severity::ERROR
628
629
  ((Watchful.private_methods + Watchful.private_instance_methods).sort - expected_methods).should == []
629
630
  aspect.unadvise
630
631
  ((Watchful.private_methods + Watchful.private_instance_methods).sort - expected_methods).should == []
@@ -635,7 +636,7 @@ describe Aspect, "#unadvise for 'empty' aspects" do
635
636
  it "should do nothing for unadvised objects." do
636
637
  @watchful = Watchful.new
637
638
  expected_methods = @watchful.private_methods.sort
638
- aspect = Aspect.new :around, :object => @watchful, :method => /does_not_exist/, :advice => @advice
639
+ aspect = Aspect.new :around, :object => @watchful, :method => /does_not_exist/, :advice => @advice, :severity => Logger::Severity::ERROR
639
640
  (@watchful.private_methods.sort - expected_methods).should == []
640
641
  aspect.unadvise
641
642
  (@watchful.private_methods.sort - expected_methods).should == []
@@ -757,13 +758,13 @@ describe Aspect, "#unadvise for removes all traces of the aspect" do
757
758
  end
758
759
  end
759
760
 
760
- describe "invariant protection level of methods under advising and unadvising", :shared => true do
761
- it "should keep the protection level of an advised methods unchanged." do
762
- %w[public protected private].each do |protection|
761
+ %w[public protected private].each do |protection|
762
+ describe Aspect, " when advising and unadvising #{protection} methods" do
763
+ it "should keep the protection level of the advised methods unchanged." do
763
764
  meta = "#{protection}_instance_methods"
764
765
  method = "#{protection}_watchful_method"
765
766
  Watchful.send(meta).should include(method)
766
- aspect = Aspect.new(:after, :type => Watchful, :method => method.intern) {|jp, obj, *args| true }
767
+ aspect = Aspect.new(:after, :type => Watchful, :method => method.intern, :method_options => [protection.intern]) {|jp, obj, *args| true }
767
768
  Watchful.send(meta).should include(method)
768
769
  aspect.unadvise
769
770
  Watchful.send(meta).should include(method)
@@ -771,14 +772,8 @@ describe "invariant protection level of methods under advising and unadvising",
771
772
  end
772
773
  end
773
774
 
774
- describe "Aspects advising methods should keep the protection level of an advised methods unchanged." do
775
- it_should_behave_like("invariant protection level of methods under advising and unadvising")
776
- end
777
- describe "Aspects unadvising methods should restore the original protection level of the methods." do
778
- it_should_behave_like("invariant protection level of methods under advising and unadvising")
779
- end
780
775
 
781
- describe "Aspects unadvising methods for instance-type pointcuts for type-defined methods" do
776
+ describe Aspect, " when unadvising methods for instance-type pointcuts for type-defined methods" do
782
777
  class TypeDefinedMethodClass
783
778
  def inititalize; @called = false; end
784
779
  def m; @called = true; end
@@ -794,7 +789,7 @@ describe "Aspects unadvising methods for instance-type pointcuts for type-define
794
789
  end
795
790
  end
796
791
 
797
- describe "Aspects unadvising methods for instance-type pointcuts for instance-defined methods" do
792
+ describe Aspect, " when unadvising methods for instance-type pointcuts for instance-defined methods" do
798
793
  class InstanceDefinedMethodClass
799
794
  def inititalize; @called = false; end
800
795
  attr_reader :called
@@ -810,7 +805,7 @@ describe "Aspects unadvising methods for instance-type pointcuts for instance-de
810
805
  end
811
806
  end
812
807
 
813
- describe "Aspects advising methods with non-alphanumeric characters" do
808
+ describe Aspect, " when advising methods with non-alphanumeric characters" do
814
809
  module Aquarium::Aspects
815
810
  class ClassWithMethodNamesContainingOddChars
816
811
  @@method_names = []
@@ -1,6 +1,6 @@
1
1
 
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
- require File.dirname(__FILE__) + '/../spec_example_classes'
3
+ require File.dirname(__FILE__) + '/../spec_example_types'
4
4
  require 'aquarium/aspects'
5
5
 
6
6
  include Aquarium::Aspects
@@ -1,6 +1,6 @@
1
1
 
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
- require File.dirname(__FILE__) + '/../spec_example_classes'
3
+ require File.dirname(__FILE__) + '/../spec_example_types'
4
4
  require 'aquarium/aspects'
5
5
 
6
6
  include Aquarium::Aspects
@@ -1,7 +1,7 @@
1
1
  # Specifically tests behavior when two or more advices apply to the same join point(s).
2
2
 
3
3
  require File.dirname(__FILE__) + '/../spec_helper'
4
- require File.dirname(__FILE__) + '/../spec_example_classes'
4
+ require File.dirname(__FILE__) + '/../spec_example_types'
5
5
  require File.dirname(__FILE__) + '/concurrently_accessed'
6
6
  require 'aquarium/aspects'
7
7
 
@@ -2,7 +2,7 @@
2
2
  # where one advice is for the type and the other is for an object of the type.
3
3
 
4
4
  require File.dirname(__FILE__) + '/../spec_helper'
5
- require File.dirname(__FILE__) + '/../spec_example_classes'
5
+ require File.dirname(__FILE__) + '/../spec_example_types'
6
6
  require File.dirname(__FILE__) + '/concurrently_accessed'
7
7
  require 'aquarium/aspects'
8
8
 
@@ -1,529 +1,539 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
- require File.dirname(__FILE__) + '/../../spec_example_classes'
2
+ require File.dirname(__FILE__) + '/../../spec_example_types'
3
3
  require 'aquarium/aspects/dsl/aspect_dsl'
4
4
 
5
5
  class DSLClass
6
6
  include Aquarium::Aspects::DSL::AspectDSL
7
7
  end
8
8
 
9
- describe "DSL method #before" do
10
- before :each do
9
+ describe "Aquarium::Aspects::DSL::AspectDSL" do
10
+ before :all do
11
11
  @advice = proc {|jp, obj, *args| "advice"}
12
- @aspects = []
13
- end
14
- after :each do
15
- @aspects.each {|a| a.unadvise}
12
+ @pointcut_opts = {:calls_to => :public_watchful_method, :in_type => Watchful}
16
13
  end
17
14
 
18
- it "should be equivalent to advise :before." do
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
- @aspects[1].should == @aspects[0]
15
+ describe "DSL method #before" do
16
+ before :each do
17
+ @aspects = []
18
+ end
19
+ after :each do
20
+ @aspects.each {|a| a.unadvise}
21
+ end
22
+
23
+ it "should be equivalent to advise :before." do
24
+ @aspects << DSLClass.advise(:before, :noop => true, :pointcut => @pointcut_opts, &@advice)
25
+ @aspects << DSLClass.before( :noop => true, :pointcut => @pointcut_opts, &@advice)
26
+ @aspects[1].should == @aspects[0]
27
+ end
22
28
  end
23
- end
24
29
 
25
- describe "DSL method #after" do
26
- before :each do
27
- @advice = proc {|jp, obj, *args| "advice"}
28
- @aspects = []
29
- end
30
- after :each do
31
- @aspects.each {|a| a.unadvise}
32
- end
30
+ describe "DSL method #after" do
31
+ before :each do
32
+ @aspects = []
33
+ end
34
+ after :each do
35
+ @aspects.each {|a| a.unadvise}
36
+ end
33
37
 
34
- it "should be equivalent to advise :after." do
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
- @aspects[1].should == @aspects[0]
38
+ it "should be equivalent to advise :after." do
39
+ @aspects << DSLClass.advise(:after, :noop => true, :pointcut => @pointcut_opts, &@advice)
40
+ @aspects << DSLClass.after( :noop => true, :pointcut => @pointcut_opts, &@advice)
41
+ @aspects[1].should == @aspects[0]
42
+ end
38
43
  end
39
- end
40
44
 
41
- describe "DSL method #after_raising_within_or_returning_from" do
42
- before :each do
43
- @dsl = DSLClass.new
44
- @advice = proc {|jp, obj, *args| "advice"}
45
- @aspects = []
46
- end
47
- after :each do
48
- @aspects.each {|a| a.unadvise}
49
- end
45
+ describe "DSL method #after_raising_within_or_returning_from" do
46
+ before :each do
47
+ @dsl = DSLClass.new
48
+ @advice = proc {|jp, obj, *args| "advice"}
49
+ @aspects = []
50
+ end
51
+ after :each do
52
+ @aspects.each {|a| a.unadvise}
53
+ end
50
54
 
51
- it "should be equivalent to advise :after." do
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
- @aspects[1].should == @aspects[0]
55
+ it "should be equivalent to advise :after." do
56
+ @aspects << DSLClass.after( :noop => true, :pointcut => @pointcut_opts, &@advice)
57
+ @aspects << DSLClass.after_raising_within_or_returning_from(:noop => true, :pointcut => @pointcut_opts, &@advice)
58
+ @aspects[1].should == @aspects[0]
59
+ end
55
60
  end
56
- end
57
61
 
58
- describe "DSL method #after_returning" do
59
- before :each do
60
- @dsl = DSLClass.new
61
- @advice = proc {|jp, obj, *args| "advice"}
62
- @aspects = []
63
- end
64
- after :each do
65
- @aspects.each {|a| a.unadvise}
66
- end
62
+ describe "DSL method #after_returning" do
63
+ before :each do
64
+ @dsl = DSLClass.new
65
+ @advice = proc {|jp, obj, *args| "advice"}
66
+ @aspects = []
67
+ end
68
+ after :each do
69
+ @aspects.each {|a| a.unadvise}
70
+ end
67
71
 
68
- it "should be equivalent to advise :after_returning." do
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
- @aspects[1].should == @aspects[0]
72
+ it "should be equivalent to advise :after_returning." do
73
+ @aspects << DSLClass.advise(:after_returning, :noop => true, :pointcut => @pointcut_opts, &@advice)
74
+ @aspects << DSLClass.after_returning( :noop => true, :pointcut => @pointcut_opts, &@advice)
75
+ @aspects[1].should == @aspects[0]
76
+ end
72
77
  end
73
- end
74
78
 
75
- describe "DSL method #after_returning_from" do
76
- before :each do
77
- @dsl = DSLClass.new
78
- @advice = proc {|jp, obj, *args| "advice"}
79
- @aspects = []
80
- end
81
- after :each do
82
- @aspects.each {|a| a.unadvise}
83
- end
79
+ describe "DSL method #after_returning_from" do
80
+ before :each do
81
+ @dsl = DSLClass.new
82
+ @advice = proc {|jp, obj, *args| "advice"}
83
+ @aspects = []
84
+ end
85
+ after :each do
86
+ @aspects.each {|a| a.unadvise}
87
+ end
84
88
 
85
- it "should be equivalent to advise :after_returning." do
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
- @aspects[1].should == @aspects[0]
89
+ it "should be equivalent to advise :after_returning." do
90
+ @aspects << DSLClass.advise(:after_returning, :noop => true, :pointcut => @pointcut_opts, &@advice)
91
+ @aspects << DSLClass.after_returning_from( :noop => true, :pointcut => @pointcut_opts, &@advice)
92
+ @aspects[1].should == @aspects[0]
93
+ end
89
94
  end
90
- end
91
95
 
92
- describe "DSL method #after_raising" do
93
- before :each do
94
- @dsl = DSLClass.new
95
- @advice = proc {|jp, obj, *args| "advice"}
96
- @aspects = []
97
- end
98
- after :each do
99
- @aspects.each {|a| a.unadvise}
100
- end
96
+ describe "DSL method #after_raising" do
97
+ before :each do
98
+ @dsl = DSLClass.new
99
+ @advice = proc {|jp, obj, *args| "advice"}
100
+ @aspects = []
101
+ end
102
+ after :each do
103
+ @aspects.each {|a| a.unadvise}
104
+ end
101
105
 
102
- it "should be equivalent to advise :after_raising." do
103
- class ThrowsUp
104
- def tosses_cookies *args; raise Exception.new(args.inspect); end
106
+ it "should be equivalent to advise :after_raising." do
107
+ class ThrowsUp
108
+ def tosses_cookies *args; raise Exception.new(args.inspect); end
109
+ end
110
+ @aspects << DSLClass.advise(:after_raising, :noop => true, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
111
+ @aspects << DSLClass.after_raising( :noop => true, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
112
+ @aspects[1].should == @aspects[0]
105
113
  end
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
- @aspects[1].should == @aspects[0]
109
114
  end
110
- end
111
115
 
112
- describe "DSL method #after_raising_within" do
113
- before :each do
114
- @dsl = DSLClass.new
115
- @advice = proc {|jp, obj, *args| "advice"}
116
- @aspects = []
117
- end
118
- after :each do
119
- @aspects.each {|a| a.unadvise}
120
- end
116
+ describe "DSL method #after_raising_within" do
117
+ before :each do
118
+ @dsl = DSLClass.new
119
+ @advice = proc {|jp, obj, *args| "advice"}
120
+ @aspects = []
121
+ end
122
+ after :each do
123
+ @aspects.each {|a| a.unadvise}
124
+ end
121
125
 
122
- it "should be equivalent to advise :after_raising." do
123
- class ThrowsUp
124
- def tosses_cookies *args; raise Exception.new(args.inspect); end
126
+ it "should be equivalent to advise :after_raising." do
127
+ class ThrowsUp
128
+ def tosses_cookies *args; raise Exception.new(args.inspect); end
129
+ end
130
+ @aspects << DSLClass.advise(:after_raising, :noop => true, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
131
+ @aspects << DSLClass.after_raising_within( :noop => true, :pointcut => {:sending_messages_to => :tosses_cookies, :in_type => ThrowsUp}, &@advice)
132
+ @aspects[1].should == @aspects[0]
125
133
  end
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
- @aspects[1].should == @aspects[0]
129
134
  end
130
- end
131
135
 
132
- describe "DSL method #before_and_after" do
133
- before :each do
134
- @dsl = DSLClass.new
135
- @advice = proc {|jp, obj, *args| "advice"}
136
- @aspects = []
137
- end
138
- after :each do
139
- @aspects.each {|a| a.unadvise}
140
- end
136
+ describe "DSL method #before_and_after" do
137
+ before :each do
138
+ @dsl = DSLClass.new
139
+ @advice = proc {|jp, obj, *args| "advice"}
140
+ @aspects = []
141
+ end
142
+ after :each do
143
+ @aspects.each {|a| a.unadvise}
144
+ end
141
145
 
142
- it "should be equivalent to advise :before, :after." do
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
- @aspects[1].should == @aspects[0]
146
+ it "should be equivalent to advise :before, :after." do
147
+ @aspects << DSLClass.advise(:before, :after, :noop => true, :pointcut => @pointcut_opts, &@advice)
148
+ @aspects << DSLClass.before_and_after( :noop => true, :pointcut => @pointcut_opts, &@advice)
149
+ @aspects[1].should == @aspects[0]
150
+ end
146
151
  end
147
- end
148
152
 
149
- describe "DSL method #before_and_after_raising_within_or_returning_from" do
150
- before :each do
151
- @dsl = DSLClass.new
152
- @advice = proc {|jp, obj, *args| "advice"}
153
- @aspects = []
154
- end
155
- after :each do
156
- @aspects.each {|a| a.unadvise}
157
- end
153
+ describe "DSL method #before_and_after_raising_within_or_returning_from" do
154
+ before :each do
155
+ @dsl = DSLClass.new
156
+ @advice = proc {|jp, obj, *args| "advice"}
157
+ @aspects = []
158
+ end
159
+ after :each do
160
+ @aspects.each {|a| a.unadvise}
161
+ end
158
162
 
159
- it "should be equivalent to advise :before and advise :after." do
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
- @aspects[1].should == @aspects[0]
163
+ it "should be equivalent to advise :before and advise :after." do
164
+ @aspects << DSLClass.advise(:before, :after, :noop => true, :pointcut => @pointcut_opts, &@advice)
165
+ @aspects << DSLClass.before_and_after_raising_within_or_returning_from(:noop => true, :pointcut => @pointcut_opts, &@advice)
166
+ @aspects[1].should == @aspects[0]
167
+ end
163
168
  end
164
- end
165
169
 
166
- describe "DSL method #before_and_after_returning" do
167
- before :each do
168
- @dsl = DSLClass.new
169
- @advice = proc {|jp, obj, *args| "advice"}
170
- @aspects = []
171
- end
172
- after :each do
173
- @aspects.each {|a| a.unadvise}
174
- end
170
+ describe "DSL method #before_and_after_returning" do
171
+ before :each do
172
+ @dsl = DSLClass.new
173
+ @advice = proc {|jp, obj, *args| "advice"}
174
+ @aspects = []
175
+ end
176
+ after :each do
177
+ @aspects.each {|a| a.unadvise}
178
+ end
175
179
 
176
- it "should be equivalent to advise :before and advise :after_returning." do
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
- @aspects[1].should == @aspects[0]
180
+ it "should be equivalent to advise :before and advise :after_returning." do
181
+ @aspects << DSLClass.advise(:before, :after_returning, :noop => true, :pointcut => @pointcut_opts, &@advice)
182
+ @aspects << DSLClass.before_and_after_returning( :noop => true, :pointcut => @pointcut_opts, &@advice)
183
+ @aspects[1].should == @aspects[0]
184
+ end
180
185
  end
181
- end
182
186
 
183
- describe "DSL method #before_and_after_returning_from" do
184
- before :each do
185
- @dsl = DSLClass.new
186
- @advice = proc {|jp, obj, *args| "advice"}
187
- @aspects = []
188
- end
189
- after :each do
190
- @aspects.each {|a| a.unadvise}
191
- end
187
+ describe "DSL method #before_and_after_returning_from" do
188
+ before :each do
189
+ @dsl = DSLClass.new
190
+ @advice = proc {|jp, obj, *args| "advice"}
191
+ @aspects = []
192
+ end
193
+ after :each do
194
+ @aspects.each {|a| a.unadvise}
195
+ end
192
196
 
193
- it "should be equivalent to advise :before and advise :after_returning." do
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
- @aspects[1].should == @aspects[0]
197
+ it "should be equivalent to advise :before and advise :after_returning." do
198
+ @aspects << DSLClass.advise(:before, :after_returning, :noop => true, :pointcut => @pointcut_opts, &@advice)
199
+ @aspects << DSLClass.before_and_after_returning_from( :noop => true, :pointcut => @pointcut_opts, &@advice)
200
+ @aspects[1].should == @aspects[0]
201
+ end
197
202
  end
198
- end
199
203
 
200
- describe "DSL method #before_and_after_raising" do
201
- before :each do
202
- @dsl = DSLClass.new
203
- @advice = proc {|jp, obj, *args| "advice"}
204
- @aspects = []
205
- end
206
- after :each do
207
- @aspects.each {|a| a.unadvise}
208
- end
204
+ describe "DSL method #before_and_after_raising" do
205
+ before :each do
206
+ @dsl = DSLClass.new
207
+ @advice = proc {|jp, obj, *args| "advice"}
208
+ @aspects = []
209
+ end
210
+ after :each do
211
+ @aspects.each {|a| a.unadvise}
212
+ end
209
213
 
210
- it "should be equivalent to advise :before and advise :after_raising." do
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
- @aspects[1].should == @aspects[0]
214
+ it "should be equivalent to advise :before and advise :after_raising." do
215
+ @aspects << DSLClass.advise(:before, :after_raising, :noop => true, :pointcut => @pointcut_opts, &@advice)
216
+ @aspects << DSLClass.before_and_after_raising( :noop => true, :pointcut => @pointcut_opts, &@advice)
217
+ @aspects[1].should == @aspects[0]
218
+ end
214
219
  end
215
- end
216
220
 
217
- describe "DSL method #around" do
218
- before :each do
219
- @dsl = DSLClass.new
220
- @advice = proc {|jp, obj, *args| "advice"}
221
- @aspects = []
222
- end
223
- after :each do
224
- @aspects.each {|a| a.unadvise}
225
- end
221
+ describe "DSL method #around" do
222
+ before :each do
223
+ @dsl = DSLClass.new
224
+ @advice = proc {|jp, obj, *args| "advice"}
225
+ @aspects = []
226
+ end
227
+ after :each do
228
+ @aspects.each {|a| a.unadvise}
229
+ end
226
230
 
227
- it "should be equivalent to advise :around." do
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
- @aspects[1].should == @aspects[0]
231
+ it "should be equivalent to advise :around." do
232
+ @aspects << DSLClass.advise(:around, :noop => true, :pointcut => @pointcut_opts, &@advice)
233
+ @aspects << DSLClass.around( :noop => true, :pointcut => @pointcut_opts, &@advice)
234
+ @aspects[1].should == @aspects[0]
235
+ end
231
236
  end
232
- end
233
237
 
234
- describe "DSL method #advise, when determining the \"self\" to advise," do
235
- before :each do
236
- @aspects = []
237
- end
238
- after :each do
239
- @aspects.each {|a| a.unadvise}
240
- end
238
+ describe "DSL method #advise, when determining the \"self\" to advise," do
239
+ before :each do
240
+ @aspects = []
241
+ end
242
+ after :each do
243
+ @aspects.each {|a| a.unadvise}
244
+ end
241
245
 
242
- it "should ignore the default object \"self\" when an :object is specified." do
243
- class Watchful1
244
- include Aquarium::Aspects::DSL::AspectDSL
245
- @@watchful = Watchful1.new
246
- @@aspect = after(:invoking => :public_watchful_method, :on_object => @@watchful) {|jp, obj, *args|}
247
- def self.watchful; @@watchful; end
248
- def self.aspect; @@aspect; end
246
+ it "should ignore the default object \"self\" when an :object is specified." do
247
+ class Watchful1
248
+ include Aquarium::Aspects::DSL::AspectDSL
249
+ def public_watchful_method; end
250
+ @@watchful = Watchful1.new
251
+ @@aspect = after(:invoking => :public_watchful_method, :on_object => @@watchful) {|jp, obj, *args|}
252
+ def self.watchful; @@watchful; end
253
+ def self.aspect; @@aspect; end
254
+ end
255
+ @aspects << Watchful1.after(:invoking => :public_watchful_method, :on_object => Watchful1.watchful) {|jp, obj, *args|}
256
+ @aspects << Watchful1.aspect
257
+ @aspects[0].join_points_matched.should_not be_empty
258
+ @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
259
+ @aspects[1].pointcuts.should == @aspects[0].pointcuts
249
260
  end
250
- @aspects << Watchful1.after(:invoking => :public_watchful_method, :on_object => Watchful1.watchful) {|jp, obj, *args|}
251
- @aspects << Watchful1.aspect
252
- @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
253
- @aspects[1].pointcuts.should == @aspects[0].pointcuts
254
- end
255
261
 
256
- it "should ignore the default object \"self\" when a :type is specified." do
257
- class Watchful2
258
- include Aquarium::Aspects::DSL::AspectDSL
259
- @@aspect = after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
260
- def self.aspect; @@aspect; end
262
+ it "should ignore the default object \"self\" when a :type is specified." do
263
+ class Watchful2
264
+ include Aquarium::Aspects::DSL::AspectDSL
265
+ def public_watchful_method; end
266
+ @@aspect = after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
267
+ def self.aspect; @@aspect; end
268
+ end
269
+ @aspects << Watchful2.after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
270
+ @aspects << Watchful2.aspect
271
+ @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
272
+ @aspects[1].pointcuts.should == @aspects[0].pointcuts
261
273
  end
262
- @aspects << Watchful2.after(:calls_to => :public_watchful_method, :in_type => Watchful2) {|jp, obj, *args|}
263
- @aspects << Watchful2.aspect
264
- @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
265
- @aspects[1].pointcuts.should == @aspects[0].pointcuts
266
274
  end
267
- end
268
275
 
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
276
+ describe "DSL method #advise, when determining the type or object to advise," do
277
+ before :each do
278
+ @aspects = []
279
+ end
280
+ after :each do
281
+ @aspects.each {|a| a.unadvise}
282
+ end
283
283
 
284
- it "should infer the type as \"self\" when no :object, :type, or :pointcut is specified." do
285
- @aspects << WatchfulSelf.after(:calls_to => :public_watchful_method, :in_type => WatchfulSelf) {|jp, obj, *args|}
286
284
  class WatchfulSelf
287
- @@aspect = after(:method => :public_watchful_method) {|jp, obj, *args|}
285
+ include Aquarium::Aspects::DSL::AspectDSL
286
+ @@aspect = nil
287
+ def self.aspect; @@aspect; end
288
+ def public_watchful_method; "public_watchful_method"; end
288
289
  end
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
290
 
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 << WatchfulSelf.advise(:after, :pointcut => {:invoking => :public_watchful_method, :on_object => watchful_self}) {|jp, obj, *args|}
298
- @aspects << watchful_self.after(:method => :public_watchful_method) {|jp, obj, *args|}
299
- @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
300
- end
291
+ it "should infer the type as \"self\" when no :object, :type, or :pointcut is specified." do
292
+ @aspects << WatchfulSelf.after(:calls_to => :public_watchful_method, :in_type => WatchfulSelf) {|jp, obj, *args|}
293
+ class WatchfulSelf
294
+ @@aspect = after(:method => :public_watchful_method) {|jp, obj, *args|}
295
+ end
296
+ @aspects << WatchfulSelf.aspect
297
+ @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
298
+ @aspects[1].pointcuts.should == @aspects[0].pointcuts
299
+ end
301
300
 
302
- it "should infer no types or objects if a :pointcut => {...} parameter is used and it does not specify a type or object." do
303
- @aspects << DSLClass.after(:pointcut => {:method => /method/}) {|jp, obj, *args|}
304
- @aspects[0].join_points_matched.size.should == 0
305
- end
306
- end
301
+ it "should infer the object as \"self\" when no :object, :type, or :pointcut is specified." do
302
+ watchful_self = WatchfulSelf.new
303
+ watchful_self.extend Aquarium::Aspects::DSL::AspectDSL
304
+ @aspects << WatchfulSelf.advise(:after, :pointcut => {:invoking => :public_watchful_method, :on_object => watchful_self}) {|jp, obj, *args|}
305
+ @aspects << watchful_self.after(:method => :public_watchful_method) {|jp, obj, *args|}
306
+ @aspects[1].join_points_matched.should == @aspects[0].join_points_matched
307
+ end
307
308
 
308
- describe "DSL method #advise, when parsing the parameter list," do
309
- class Watchful3
310
- include Aquarium::Aspects::DSL::AspectDSL
311
- def public_watchful_method; "public_watchful_method"; end
309
+ it "should infer no types or objects if a :pointcut => {...} parameter is used and it does not specify a type or object." do
310
+ @aspects << DSLClass.after(:pointcut => {:method => /method/}, :ignore_no_matching_join_points=>true) {|jp, obj, *args|}
311
+ @aspects[0].join_points_matched.size.should == 0
312
+ end
312
313
  end
313
314
 
314
- before :each do
315
- @aspects = []
316
- end
317
- after :each do
318
- @aspects.each {|a| a.unadvise}
319
- end
315
+ describe "DSL method #advise, when parsing the parameter list," do
316
+ class Watchful3
317
+ include Aquarium::Aspects::DSL::AspectDSL
318
+ def public_watchful_method; "public_watchful_method"; end
319
+ end
320
320
 
321
- 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
322
- @aspects << Watchful3.after(:public_watchful_method) {|jp, obj, *args|}
323
- @aspects.each do |aspect|
324
- aspect.join_points_matched.size.should == 1
325
- aspect.specification[:methods].should == Set.new([:public_watchful_method])
321
+ before :each do
322
+ @aspects = []
323
+ end
324
+ after :each do
325
+ @aspects.each {|a| a.unadvise}
326
326
  end
327
- end
328
- end
329
327
 
330
- describe "DSL method #advise, when determining instance or class methods to advise," do
331
- before :each do
332
- @aspects = []
333
- end
334
- after :each do
335
- @aspects.each {|a| a.unadvise}
328
+ 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
329
+ @aspects << Watchful3.after(:public_watchful_method) {|jp, obj, *args|}
330
+ @aspects.each do |aspect|
331
+ aspect.join_points_matched.size.should == 1
332
+ aspect.specification[:methods].should == Set.new([:public_watchful_method])
333
+ end
334
+ end
336
335
  end
337
336
 
338
- it "should treat \"ClassName.advise\" as advising instance methods, by default." do
339
- class WatchfulExampleWithSeparateAdviseCall
340
- include Aquarium::Aspects::DSL::AspectDSL
341
- def public_watchful_method *args; end
337
+ describe "DSL method #advise, when determining instance or class methods to advise," do
338
+ before :each do
339
+ @aspects = []
342
340
  end
343
- advice_called = 0
344
- WatchfulExampleWithSeparateAdviseCall.advise :before, :public_watchful_method do |jp, obj, *args|
345
- advice_called += 1
341
+ after :each do
342
+ @aspects.each {|a| a.unadvise}
343
+ end
344
+
345
+ it "should treat \"ClassName.advise\" as advising instance methods, by default." do
346
+ class WatchfulExampleWithSeparateAdviseCall
347
+ include Aquarium::Aspects::DSL::AspectDSL
348
+ def public_watchful_method *args; end
349
+ end
350
+ advice_called = 0
351
+ WatchfulExampleWithSeparateAdviseCall.advise :before, :public_watchful_method do |jp, obj, *args|
352
+ advice_called += 1
353
+ end
354
+ WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a1, :a2
355
+ WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a3, :a4
356
+ advice_called.should == 2
346
357
  end
347
- WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a1, :a2
348
- WatchfulExampleWithSeparateAdviseCall.new.public_watchful_method :a3, :a4
349
- advice_called.should == 2
350
- end
351
358
 
352
- it "should treat \"ClassName.advise\" as advising instance methods when the :instance method option is specified." do
353
- class WatchfulExampleWithSeparateAdviseCall2
354
- include Aquarium::Aspects::DSL::AspectDSL
355
- def self.class_public_watchful_method *args; end
356
- def public_watchful_method *args; end
357
- end
358
- advice_called = 0
359
- WatchfulExampleWithSeparateAdviseCall2.advise :before, :sending_messages_to => /public_watchful_method/, :on_types => WatchfulExampleWithSeparateAdviseCall2, :restricting_methods_to =>[:instance_methods] do |jp, obj, *args|
360
- advice_called += 1
361
- end
362
- WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a1, :a2
363
- WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a3, :a4
364
- advice_called.should == 0
365
- WatchfulExampleWithSeparateAdviseCall2.new.public_watchful_method :a1, :a2
366
- WatchfulExampleWithSeparateAdviseCall2.new.public_watchful_method :a3, :a4
367
- advice_called.should == 2
368
- end
359
+ it "should treat \"ClassName.advise\" as advising instance methods when the :instance method option is specified." do
360
+ class WatchfulExampleWithSeparateAdviseCall2
361
+ include Aquarium::Aspects::DSL::AspectDSL
362
+ def self.class_public_watchful_method *args; end
363
+ def public_watchful_method *args; end
364
+ end
365
+ advice_called = 0
366
+ WatchfulExampleWithSeparateAdviseCall2.advise :before, :sending_messages_to => /public_watchful_method/, :on_types => WatchfulExampleWithSeparateAdviseCall2, :restricting_methods_to =>[:instance_methods] do |jp, obj, *args|
367
+ advice_called += 1
368
+ end
369
+ WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a1, :a2
370
+ WatchfulExampleWithSeparateAdviseCall2.class_public_watchful_method :a3, :a4
371
+ advice_called.should == 0
372
+ WatchfulExampleWithSeparateAdviseCall2.new.public_watchful_method :a1, :a2
373
+ WatchfulExampleWithSeparateAdviseCall2.new.public_watchful_method :a3, :a4
374
+ advice_called.should == 2
375
+ end
369
376
 
370
- it "should treat \"ClassName.advise\" as advising class methods when the :class method option is specified." do
371
- class WatchfulExampleWithSeparateAdviseCall3
372
- include Aquarium::Aspects::DSL::AspectDSL
373
- def self.class_public_watchful_method *args; end
374
- def public_watchful_method *args; end
375
- end
376
- advice_called = 0
377
- WatchfulExampleWithSeparateAdviseCall3.advise :before, :calling => /public_watchful_method/, :restricting_methods_to =>[:class_methods] do |jp, obj, *args|
378
- advice_called += 1
379
- end
380
- WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a1, :a2
381
- WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a3, :a4
382
- advice_called.should == 2
383
- WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a1, :a2
384
- WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a3, :a4
385
- advice_called.should == 2
386
- end
377
+ it "should treat \"ClassName.advise\" as advising class methods when the :class method option is specified." do
378
+ class WatchfulExampleWithSeparateAdviseCall3
379
+ include Aquarium::Aspects::DSL::AspectDSL
380
+ def self.class_public_watchful_method *args; end
381
+ def public_watchful_method *args; end
382
+ end
383
+ advice_called = 0
384
+ WatchfulExampleWithSeparateAdviseCall3.advise :before, :calling => /public_watchful_method/, :restricting_methods_to =>[:class_methods] do |jp, obj, *args|
385
+ advice_called += 1
386
+ end
387
+ WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a1, :a2
388
+ WatchfulExampleWithSeparateAdviseCall3.class_public_watchful_method :a3, :a4
389
+ advice_called.should == 2
390
+ WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a1, :a2
391
+ WatchfulExampleWithSeparateAdviseCall3.new.public_watchful_method :a3, :a4
392
+ advice_called.should == 2
393
+ end
387
394
 
388
- it "should invoke the type-based advise for all objects when the aspect is defined by calling #advise within the class definition." do
389
- class WatchfulExampleWithBeforeAdvice
390
- include Aquarium::Aspects::DSL::AspectDSL
391
- @@advice_called = 0
392
- def public_watchful_method *args; end
393
- before :public_watchful_method do |jp, obj, *args|
394
- @@advice_called += 1
395
+ it "should invoke the type-based advise for all objects when the aspect is defined by calling #advise within the class definition." do
396
+ class WatchfulExampleWithBeforeAdvice
397
+ include Aquarium::Aspects::DSL::AspectDSL
398
+ @@advice_called = 0
399
+ def public_watchful_method *args; end
400
+ before :public_watchful_method do |jp, obj, *args|
401
+ @@advice_called += 1
402
+ end
403
+ def self.advice_called; @@advice_called; end
395
404
  end
396
- def self.advice_called; @@advice_called; end
405
+ WatchfulExampleWithBeforeAdvice.new.public_watchful_method :a1, :a2
406
+ WatchfulExampleWithBeforeAdvice.new.public_watchful_method :a3, :a4
407
+ WatchfulExampleWithBeforeAdvice.advice_called.should == 2
397
408
  end
398
- WatchfulExampleWithBeforeAdvice.new.public_watchful_method :a1, :a2
399
- WatchfulExampleWithBeforeAdvice.new.public_watchful_method :a3, :a4
400
- WatchfulExampleWithBeforeAdvice.advice_called.should == 2
401
409
  end
402
- end
403
410
 
404
- describe "DSL methods for the advice kind, when determining instance or class methods to advise," do
405
- class Watchful4
406
- include Aquarium::Aspects::DSL::AspectDSL
407
- def public_watchful_method; "public_watchful_method"; end
408
- end
411
+ describe "DSL methods for the advice kind, when determining instance or class methods to advise," do
412
+ class Watchful4
413
+ include Aquarium::Aspects::DSL::AspectDSL
414
+ def public_watchful_method; "public_watchful_method"; end
415
+ end
409
416
 
410
- before :each do
411
- @advice = proc {|jp, obj, *args| "advice"}
412
- @aspects = []
413
- end
414
- after :each do
415
- @aspects.each {|a| a.unadvise}
416
- end
417
+ before :each do
418
+ @advice = proc {|jp, obj, *args| "advice"}
419
+ @aspects = []
420
+ end
421
+ after :each do
422
+ @aspects.each {|a| a.unadvise}
423
+ end
417
424
 
418
- (Aquarium::Aspects::Advice.kinds + [:after_raising_within_or_returning_from]).each do |advice_kind|
419
- it "##{advice_kind} method should infer the first symbol parameter as the method name to advise if no other :method => ... parameter is used." do
420
- @aspects << Watchful4.method(advice_kind).call(:public_watchful_method, &@advice)
421
- @aspects.each do |aspect|
422
- aspect.join_points_matched.size.should == 1
423
- aspect.specification[:methods].should == Set.new([:public_watchful_method])
425
+ (Aquarium::Aspects::Advice.kinds + [:after_raising_within_or_returning_from]).each do |advice_kind|
426
+ it "##{advice_kind} method should infer the first symbol parameter as the method name to advise if no other :method => ... parameter is used." do
427
+ @aspects << Watchful4.method(advice_kind).call(:public_watchful_method, &@advice)
428
+ @aspects.each do |aspect|
429
+ aspect.join_points_matched.size.should == 1
430
+ aspect.specification[:methods].should == Set.new([:public_watchful_method])
431
+ end
424
432
  end
425
433
  end
426
434
  end
427
- end
428
435
 
429
- describe "Synonyms for :types" do
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
436
+ describe "Synonyms for :types" do
437
+ Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["types"].each do |key|
438
+ it "should accept :#{key} as a synonym for :types." do
439
+ advice = proc {|jp, obj, *args| "advice"}
440
+ aspect1 = DSLClass.after :noop => true, :calls_to => :public_watchful_method, :types => Watchful, &advice
441
+ aspect2 = DSLClass.after :noop => true, :calls_to => :public_watchful_method, key.intern => Watchful, &advice
442
+ aspect2.should == aspect1
443
+ aspect1.unadvise
444
+ aspect2.unadvise
445
+ end
438
446
  end
439
447
  end
440
- end
441
448
 
442
- describe "Synonyms for :objects" do
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
449
+ describe "Synonyms for :objects" do
450
+ Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["objects"].each do |key|
451
+ it "should accept :#{key} as a synonym for :objects." do
452
+ watchful = Watchful.new
453
+ advice = proc {|jp, obj, *args| "advice"}
454
+ aspect1 = DSLClass.after :noop => true, :calls_to => :public_watchful_method, :objects => watchful, &advice
455
+ aspect2 = DSLClass.after :noop => true, :calls_to => :public_watchful_method, key.intern => watchful, &advice
456
+ aspect2.should == aspect1
457
+ aspect1.unadvise
458
+ aspect2.unadvise
459
+ end
451
460
  end
452
461
  end
453
- end
454
462
 
455
- describe "Synonyms for :methods" do
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
463
+ describe "Synonyms for :methods" do
464
+ Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["methods"].each do |key|
465
+ it "should accept :#{key} as a synonym for :methods." do
466
+ advice = proc {|jp, obj, *args| "advice"}
467
+ aspect1 = DSLClass.after :noop => true, :methods => :public_watchful_method, :in_types => Watchful, &advice
468
+ aspect2 = DSLClass.after :noop => true, key.intern => :public_watchful_method, :in_types => Watchful, &advice
469
+ aspect2.should == aspect1
470
+ aspect1.unadvise
471
+ aspect2.unadvise
472
+ end
464
473
  end
465
474
  end
466
- end
467
475
 
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
476
+ describe "Synonyms for :pointcuts" do
477
+ Aquarium::Aspects::Aspect::CANONICAL_OPTIONS["pointcuts"].each do |key|
478
+ it "should accept :#{key} as a synonym for :pointcuts." do
479
+ watchful = Watchful.new
480
+ advice = proc {|jp, obj, *args| "advice"}
481
+ aspect1 = DSLClass.after :noop => true, :pointcuts => {:calls_to => :public_watchful_method, :within_objects => watchful}, &advice
482
+ aspect2 = DSLClass.after :noop => true, key.intern => {:calls_to => :public_watchful_method, :within_objects => watchful}, &advice
483
+ aspect2.should == aspect1
484
+ aspect1.unadvise
485
+ aspect2.unadvise
486
+ end
477
487
  end
478
488
  end
479
- end
480
489
 
481
- describe "DSL method #advise (or synonyms) called within a type body" do
482
- it "will not advise a method whose definition hasn't been seen yet in the type body." do
483
- class WatchfulWithMethodAlreadyDefined
484
- include Aquarium::Aspects::DSL::AspectDSL
485
- @@advice_called = 0
486
- def public_watchful_method *args; end
487
- before :public_watchful_method do |jp, obj, *args|
488
- @@advice_called += 1
490
+ describe "DSL method #advise (or synonyms) called within a type body" do
491
+ it "will not advise a method whose definition hasn't been seen yet in the type body." do
492
+ class WatchfulWithMethodAlreadyDefined
493
+ include Aquarium::Aspects::DSL::AspectDSL
494
+ @@advice_called = 0
495
+ def public_watchful_method *args; end
496
+ before :public_watchful_method do |jp, obj, *args|
497
+ @@advice_called += 1
498
+ end
499
+ def self.advice_called; @@advice_called; end
500
+ end
501
+ WatchfulWithMethodAlreadyDefined.new.public_watchful_method :a1, :a2
502
+ WatchfulWithMethodAlreadyDefined.new.public_watchful_method :a3, :a4
503
+ WatchfulWithMethodAlreadyDefined.advice_called.should == 2
504
+ class WatchfulWithMethodNotYetDefined
505
+ include Aquarium::Aspects::DSL::AspectDSL
506
+ @@advice_called = 0
507
+ before(:public_watchful_method, :ignore_no_matching_join_points=>true) {|jp, obj, *args| @@advice_called += 1}
508
+ def public_watchful_method *args; end
509
+ def self.advice_called; @@advice_called; end
489
510
  end
490
- def self.advice_called; @@advice_called; end
511
+ WatchfulWithMethodNotYetDefined.new.public_watchful_method :a1, :a2
512
+ WatchfulWithMethodNotYetDefined.new.public_watchful_method :a3, :a4
513
+ WatchfulWithMethodNotYetDefined.advice_called.should == 0
491
514
  end
492
- WatchfulWithMethodAlreadyDefined.new.public_watchful_method :a1, :a2
493
- WatchfulWithMethodAlreadyDefined.new.public_watchful_method :a3, :a4
494
- WatchfulWithMethodAlreadyDefined.advice_called.should == 2
495
- class WatchfulWithMethodNotYetDefined
496
- include Aquarium::Aspects::DSL::AspectDSL
497
- @@advice_called = 0
498
- before(:public_watchful_method) {|jp, obj, *args| @@advice_called += 1}
499
- def public_watchful_method *args; end
500
- def self.advice_called; @@advice_called; end
501
- end
502
- WatchfulWithMethodNotYetDefined.new.public_watchful_method :a1, :a2
503
- WatchfulWithMethodNotYetDefined.new.public_watchful_method :a3, :a4
504
- WatchfulWithMethodNotYetDefined.advice_called.should == 0
505
515
  end
506
- end
507
516
 
508
- describe "DSL method #pointcut" do
509
- class PC1;
510
- def doit; end
511
- end
517
+ describe "DSL method #pointcut" do
518
+ class PC1;
519
+ def doit; end
520
+ end
512
521
 
513
- it "should match equivalent join points as Pointcut.new" do
514
- pointcut1 = DSLClass.pointcut :type => PC1, :method => :doit
515
- pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC1, :method => :doit
516
- pointcut1.join_points_matched.should == pointcut2.join_points_matched
517
- pointcut1.join_points_not_matched.should == pointcut2.join_points_not_matched
518
- end
522
+ it "should match equivalent join points as Pointcut.new" do
523
+ pointcut1 = DSLClass.pointcut :type => PC1, :method => :doit
524
+ pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC1, :method => :doit
525
+ pointcut1.join_points_matched.should == pointcut2.join_points_matched
526
+ pointcut1.join_points_not_matched.should == pointcut2.join_points_not_matched
527
+ end
519
528
 
520
- it "should use self as the object if no object or type is specified." do
521
- class PC2
522
- include Aquarium::Aspects::DSL::AspectDSL
523
- POINTCUT = pointcut :method => :doit
529
+ it "should use self as the object if no object or type is specified." do
530
+ class PC2
531
+ include Aquarium::Aspects::DSL::AspectDSL
532
+ POINTCUT = pointcut :method => :doit
533
+ end
534
+ pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC2, :method => :doit
535
+ PC2::POINTCUT.join_points_matched.should == pointcut2.join_points_matched
536
+ PC2::POINTCUT.join_points_not_matched.should == pointcut2.join_points_not_matched
524
537
  end
525
- pointcut2 = Aquarium::Aspects::Pointcut.new :type => PC2, :method => :doit
526
- PC2::POINTCUT.join_points_matched.should == pointcut2.join_points_matched
527
- PC2::POINTCUT.join_points_not_matched.should == pointcut2.join_points_not_matched
528
538
  end
529
539
  end