aquarium 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Aquarium.ipr +253 -0
- data/Aquarium.iws +629 -0
- data/CHANGES +43 -0
- data/UPGRADE +13 -7
- data/examples/method_tracing_example_spec.rb +4 -1
- data/lib/aquarium/aspects/aspect.rb +28 -11
- data/lib/aquarium/aspects/exclusion_handler.rb +1 -1
- data/lib/aquarium/aspects/join_point.rb +58 -14
- data/lib/aquarium/aspects/pointcut.rb +5 -6
- data/lib/aquarium/extras/design_by_contract.rb +1 -1
- data/lib/aquarium/finders/method_finder.rb +1 -4
- data/lib/aquarium/finders/type_finder.rb +8 -1
- data/lib/aquarium/utils.rb +1 -0
- data/lib/aquarium/utils/default_logger.rb +20 -0
- data/lib/aquarium/utils/options_utils.rb +74 -12
- data/lib/aquarium/utils/type_utils.rb +1 -7
- data/lib/aquarium/version.rb +1 -1
- data/spec/aquarium/aspects/advice_chain_node_spec.rb +1 -1
- data/spec/aquarium/aspects/advice_spec.rb +1 -1
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +1531 -1465
- data/spec/aquarium/aspects/aspect_spec.rb +22 -27
- data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +1 -1
- data/spec/aquarium/aspects/aspect_with_subtypes_spec.rb +1 -1
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +1 -1
- data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +1 -1
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +434 -424
- data/spec/aquarium/aspects/join_point_spec.rb +27 -4
- data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +98 -102
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +95 -107
- data/spec/aquarium/aspects/pointcut_spec.rb +1365 -1382
- data/spec/aquarium/extensions/hash_spec.rb +1 -1
- data/spec/aquarium/extensions/set_spec.rb +1 -1
- data/spec/aquarium/finders/finder_result_spec.rb +1 -1
- data/spec/aquarium/finders/method_finder_spec.rb +1 -1
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +63 -145
- data/spec/aquarium/{spec_example_classes.rb → spec_example_types.rb} +35 -0
- data/spec/aquarium/utils/default_logger_spec.rb +28 -0
- data/spec/aquarium/utils/hash_utils_spec.rb +1 -1
- data/spec/aquarium/utils/logic_error_spec.rb +1 -1
- data/spec/aquarium/utils/name_utils_spec.rb +1 -1
- data/spec/aquarium/utils/nil_object_spec.rb +1 -1
- data/spec/aquarium/utils/options_utils_spec.rb +122 -0
- data/spec/aquarium/utils/set_utils_spec.rb +1 -1
- metadata +9 -4
@@ -1,12 +1,13 @@
|
|
1
1
|
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
-
require File.dirname(__FILE__) + '/../
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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 "
|
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
|
-
|
761
|
-
|
762
|
-
|
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 "
|
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 "
|
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 "
|
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,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__) + '/../
|
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__) + '/../
|
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__) + '/../../
|
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
|
10
|
-
before :
|
9
|
+
describe "Aquarium::Aspects::DSL::AspectDSL" do
|
10
|
+
before :all do
|
11
11
|
@advice = proc {|jp, obj, *args| "advice"}
|
12
|
-
@
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
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
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
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
|
-
|
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
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
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
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
339
|
-
|
340
|
-
|
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
|
-
|
344
|
-
|
345
|
-
|
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
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
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
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
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
|
-
|
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
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
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
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
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
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
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
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
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
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
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
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
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
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
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
|
-
|
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
|
-
|
510
|
-
|
511
|
-
|
517
|
+
describe "DSL method #pointcut" do
|
518
|
+
class PC1;
|
519
|
+
def doit; end
|
520
|
+
end
|
512
521
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
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
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
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
|