aquarium 0.3.1 → 0.4.0
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/CHANGES +50 -0
- data/README +35 -6
- data/RELEASE-PLAN +8 -5
- data/Rakefile +17 -1
- data/UPGRADE +5 -0
- data/lib/aquarium/aspects/advice.rb +6 -6
- data/lib/aquarium/aspects/aspect.rb +11 -17
- data/lib/aquarium/aspects/join_point.rb +5 -5
- data/lib/aquarium/aspects/pointcut.rb +68 -40
- data/lib/aquarium/finders/method_finder.rb +1 -0
- data/lib/aquarium/finders/type_finder.rb +12 -8
- data/lib/aquarium/utils/default_logger.rb +1 -0
- data/lib/aquarium/utils/method_utils.rb +4 -4
- data/lib/aquarium/utils/name_utils.rb +3 -3
- data/lib/aquarium/utils/type_utils.rb +25 -10
- data/lib/aquarium/version.rb +2 -2
- data/spec/aquarium/aspects/advice_spec.rb +13 -1
- data/spec/aquarium/aspects/aspect_spec.rb +63 -44
- data/spec/aquarium/aspects/join_point_spec.rb +1 -1
- data/spec/aquarium/aspects/pointcut_spec.rb +22 -10
- data/spec/aquarium/finders/method_finder_spec.rb +3 -2
- data/spec/aquarium/finders/type_finder_spec.rb +2 -2
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +8 -8
- data/spec/aquarium/utils/method_utils_spec.rb +17 -6
- data/spec/aquarium/utils/type_utils_spec.rb +45 -23
- metadata +3 -3
@@ -20,13 +20,13 @@ module Aquarium
|
|
20
20
|
|
21
21
|
def self.visibility type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
|
22
22
|
find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
|
23
|
-
|
23
|
+
protection
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.has_method type_or_instance, method_sym, class_or_instance_only = nil, include_ancestors = true
|
28
28
|
found = find_method(type_or_instance, method_sym, class_or_instance_only, include_ancestors) do |t_or_o, msym, protection|
|
29
|
-
|
29
|
+
true
|
30
30
|
end
|
31
31
|
found ? true : false # found could be nil; return false, if so
|
32
32
|
end
|
@@ -36,8 +36,8 @@ module Aquarium
|
|
36
36
|
meta_method_suffixes.each do |suffix|
|
37
37
|
%w[public protected private].each do |protection|
|
38
38
|
meta_method = "#{protection}_#{suffix}"
|
39
|
-
|
40
|
-
if
|
39
|
+
found_methods = type_or_instance.send(meta_method, include_ancestors)
|
40
|
+
if found_methods.include?(method_sym.to_s)
|
41
41
|
return yield(type_or_instance, method_sym, protection.intern)
|
42
42
|
end
|
43
43
|
end
|
@@ -6,7 +6,7 @@ module Aquarium
|
|
6
6
|
module Utils
|
7
7
|
module NameUtils
|
8
8
|
|
9
|
-
@@
|
9
|
+
@@char_expr_map = {
|
10
10
|
'=' => '_equal_',
|
11
11
|
'?' => '_questionmark_',
|
12
12
|
'!' => '_exclamationmark_',
|
@@ -51,8 +51,8 @@ module Aquarium
|
|
51
51
|
|
52
52
|
def self.make_valid_attr_name_from_method_name method_name
|
53
53
|
new_name = method_name.to_s
|
54
|
-
@@
|
55
|
-
new_name.gsub!
|
54
|
+
@@char_expr_map.keys.sort{|x,y| y.length <=> x.length}.each do |expr|
|
55
|
+
new_name.gsub! expr, @@char_expr_map[expr]
|
56
56
|
end
|
57
57
|
new_name.intern
|
58
58
|
end
|
@@ -6,31 +6,46 @@ module Aquarium
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.descendents clazz
|
9
|
-
|
10
|
-
result =
|
9
|
+
visited = [Class, Object, Module, clazz]
|
10
|
+
result = [clazz]
|
11
|
+
Module.constants.each do |const|
|
11
12
|
mod = Module.class_eval(const)
|
12
13
|
if mod.respond_to?(:ancestors)
|
13
14
|
result << mod if mod.ancestors.include?(clazz)
|
14
|
-
do_descendents clazz, mod,
|
15
|
+
do_descendents clazz, mod, visited, result
|
15
16
|
end
|
16
|
-
result
|
17
17
|
end
|
18
18
|
result.uniq
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
22
22
|
|
23
|
+
# For JRuby classes, we have to "__x__" forms of the reflection methods that don't end in '?'.
|
24
|
+
# That includes "send", so we do some ugly switching, rather than call "mod.send(method_name)"
|
25
|
+
# or "mod.__send__(method_name)"!
|
23
26
|
def self.do_descendents clazz, visiting_module, visited, result
|
24
27
|
visited << visiting_module
|
25
|
-
|
28
|
+
use_underscore_methods = use_underscore_methods? visiting_module
|
29
|
+
nested_constants = use_underscore_methods ? visiting_module.__constants__ : visiting_module.constants
|
30
|
+
nested_constants.each do |const|
|
26
31
|
next unless visiting_module.const_defined?(const)
|
27
|
-
|
28
|
-
next if visited.include?(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
nested_module = use_underscore_methods ? visiting_module.__const_get__(const) : visiting_module.const_get(const)
|
33
|
+
next if visited.include?(nested_module)
|
34
|
+
next unless responds_to_ancestors?(nested_module)
|
35
|
+
use_underscore_methods2 = use_underscore_methods? nested_module
|
36
|
+
modules_ancestors = use_underscore_methods2 ? nested_module.__ancestors__ : nested_module.ancestors
|
37
|
+
result << nested_module if modules_ancestors.include?(clazz)
|
38
|
+
do_descendents clazz, nested_module, visited, result
|
32
39
|
end
|
33
40
|
end
|
41
|
+
|
42
|
+
def self.use_underscore_methods? mod
|
43
|
+
mod.respond_to?(:__constants__)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.responds_to_ancestors? mod
|
47
|
+
mod.respond_to?(:ancestors) or mod.respond_to?(:__ancestors__)
|
48
|
+
end
|
34
49
|
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/aquarium/version.rb
CHANGED
@@ -25,7 +25,7 @@ describe Advice, "#invoke_original_join_point" do
|
|
25
25
|
def counter; @counter; end
|
26
26
|
end
|
27
27
|
|
28
|
-
it "should invoke the original join_point" do
|
28
|
+
it "should invoke the original join_point with multiple advices" do
|
29
29
|
aspect1 = Aspect.new :before, :type => InvocationCounter, :method => :increment do |jp, o|
|
30
30
|
jp.invoke_original_join_point
|
31
31
|
end
|
@@ -39,6 +39,18 @@ describe Advice, "#invoke_original_join_point" do
|
|
39
39
|
aspect1.unadvise
|
40
40
|
aspect2.unadvise
|
41
41
|
end
|
42
|
+
|
43
|
+
Advice.kinds.each do |kind|
|
44
|
+
it "should invoke the original join_point with #{kind} advice" do
|
45
|
+
aspect = Aspect.new kind, :type => InvocationCounter, :method => :increment do |jp, o|
|
46
|
+
jp.invoke_original_join_point
|
47
|
+
end
|
48
|
+
ic = InvocationCounter.new
|
49
|
+
ic.increment
|
50
|
+
ic.counter == 1
|
51
|
+
aspect.unadvise
|
52
|
+
end
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
describe Advice, "that raises an exception" do
|
@@ -618,6 +618,19 @@ describe Aspect, " with advice that calls JoinPoint#invoke_original_join_point"
|
|
618
618
|
end
|
619
619
|
end
|
620
620
|
|
621
|
+
describe Aspect, "#unadvise called more than once on the same aspect" do
|
622
|
+
before(:all) do
|
623
|
+
@advice = Proc.new {}
|
624
|
+
end
|
625
|
+
|
626
|
+
it "should do nothing on the second invocation." do
|
627
|
+
aspect = Aspect.new :around, :type => Watchful, :method => /does_not_exist/, :advice => @advice, :severity => Logger::Severity::ERROR
|
628
|
+
aspect.unadvise
|
629
|
+
lambda {aspect.unadvise}.should_not raise_error
|
630
|
+
lambda {aspect.unadvise}.should_not raise_error
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
621
634
|
describe Aspect, "#unadvise for 'empty' aspects" do
|
622
635
|
before(:all) do
|
623
636
|
@advice = Proc.new {}
|
@@ -645,7 +658,7 @@ describe Aspect, "#unadvise for 'empty' aspects" do
|
|
645
658
|
end
|
646
659
|
end
|
647
660
|
|
648
|
-
describe Aspect, "#unadvise
|
661
|
+
describe Aspect, "#unadvise clean up" do
|
649
662
|
before(:all) do
|
650
663
|
@advice = Proc.new {}
|
651
664
|
@watchful = Watchful.new
|
@@ -704,57 +717,63 @@ describe Aspect, "#unadvise for removes all traces of the aspect" do
|
|
704
717
|
it "should remove all advice added by an object-based aspect." do
|
705
718
|
do_unadvise_spec({:object => @watchful, :method_options => :exclude_ancestor_methods}, :get_object_methods)
|
706
719
|
end
|
720
|
+
end
|
721
|
+
|
722
|
+
module Aquarium
|
723
|
+
class FooForPrivateCheck
|
724
|
+
def bar; end
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
728
|
+
describe Aspect, "#unadvise clean up when all advices have been removed" do
|
729
|
+
before(:all) do
|
730
|
+
@advice = Proc.new {}
|
731
|
+
@aspect1 = @aspect2 = nil
|
732
|
+
end
|
733
|
+
|
734
|
+
def check_cleanup before_methods, before_class_variables
|
735
|
+
after = yield
|
736
|
+
(after[0] - before_methods).should_not == []
|
737
|
+
(after[1] - before_class_variables).should_not == []
|
738
|
+
@aspect1.unadvise
|
739
|
+
after = yield
|
740
|
+
(after[0] - before_methods).should_not == []
|
741
|
+
(after[1] - before_class_variables).should_not == []
|
742
|
+
@aspect2.unadvise
|
743
|
+
after = yield
|
744
|
+
(after[0] - before_methods).should == []
|
745
|
+
(after[1] - before_class_variables).should == []
|
746
|
+
end
|
707
747
|
|
708
|
-
it "should remove all advice overhead
|
709
|
-
|
710
|
-
|
748
|
+
it "should remove all advice overhead for pointcut-based aspects." do
|
749
|
+
before_methods = Aquarium::FooForPrivateCheck.private_instance_methods.sort
|
750
|
+
before_class_variables = Aquarium::FooForPrivateCheck.class_variables.sort
|
751
|
+
@aspect1 = Aspect.new(:before, :pointcut => {:type => Aquarium::FooForPrivateCheck, :method_options => :exclude_ancestor_methods}) {|jp, obj, *args| true}
|
752
|
+
@aspect2 = Aspect.new(:after, :pointcut => {:type => Aquarium::FooForPrivateCheck, :method_options => :exclude_ancestor_methods}) {|jp, obj, *args| true}
|
753
|
+
check_cleanup(before_methods, before_class_variables) do
|
754
|
+
[Aquarium::FooForPrivateCheck.private_instance_methods.sort, Aquarium::FooForPrivateCheck.class_variables.sort]
|
711
755
|
end
|
712
|
-
before = Foo.private_instance_methods.sort
|
713
|
-
aspect1 = Aspect.new(:before, :pointcut => {:type => Foo, :method_options => :exclude_ancestor_methods}) {|jp, obj, *args| true}
|
714
|
-
aspect2 = Aspect.new(:after, :pointcut => {:type => Foo, :method_options => :exclude_ancestor_methods}) {|jp, obj, *args| true}
|
715
|
-
after = Foo.private_instance_methods
|
716
|
-
(after - before).should_not == []
|
717
|
-
aspect1.unadvise
|
718
|
-
after = Foo.private_instance_methods
|
719
|
-
(after - before).should_not == []
|
720
|
-
aspect2.unadvise
|
721
|
-
after = Foo.private_instance_methods
|
722
|
-
(after - before).should == []
|
723
756
|
end
|
724
757
|
|
725
|
-
it "should remove all advice overhead
|
726
|
-
|
727
|
-
|
758
|
+
it "should remove all advice overhead for type-based aspects." do
|
759
|
+
before_methods = Aquarium::FooForPrivateCheck.private_instance_methods.sort
|
760
|
+
before_class_variables = Aquarium::FooForPrivateCheck.class_variables.sort
|
761
|
+
@aspect1 = Aspect.new(:before, :type => Aquarium::FooForPrivateCheck, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
762
|
+
@aspect2 = Aspect.new(:after, :type => Aquarium::FooForPrivateCheck, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
763
|
+
check_cleanup(before_methods, before_class_variables) do
|
764
|
+
[Aquarium::FooForPrivateCheck.private_instance_methods.sort, Aquarium::FooForPrivateCheck.class_variables.sort]
|
728
765
|
end
|
729
|
-
before = Foo.private_instance_methods.sort
|
730
|
-
aspect1 = Aspect.new(:before, :type => Foo, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
731
|
-
aspect2 = Aspect.new(:after, :type => Foo, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
732
|
-
after = Foo.private_instance_methods
|
733
|
-
(after - before).should_not == []
|
734
|
-
aspect1.unadvise
|
735
|
-
after = Foo.private_instance_methods
|
736
|
-
(after - before).should_not == []
|
737
|
-
aspect2.unadvise
|
738
|
-
after = Foo.private_instance_methods
|
739
|
-
(after - before).should == []
|
740
766
|
end
|
741
767
|
|
742
|
-
it "should remove all advice overhead
|
743
|
-
|
744
|
-
|
768
|
+
it "should remove all advice overhead for object-based aspects." do
|
769
|
+
object = Aquarium::FooForPrivateCheck.new
|
770
|
+
before_methods = object.private_methods.sort
|
771
|
+
before_class_variables = (class << object; self.class_variables.sort; end)
|
772
|
+
@aspect1 = Aspect.new(:before, :object => object, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
773
|
+
@aspect2 = Aspect.new(:after, :object => object, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
774
|
+
check_cleanup(before_methods, before_class_variables) do
|
775
|
+
[object.private_methods.sort, (class << object; self.class_variables.sort; end)]
|
745
776
|
end
|
746
|
-
overhead = Overhead.new
|
747
|
-
before = overhead.private_methods.sort
|
748
|
-
aspect1 = Aspect.new(:before, :object => overhead, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
749
|
-
aspect2 = Aspect.new(:after, :object => overhead, :method_options => :exclude_ancestor_methods) {|jp, obj, *args| true}
|
750
|
-
after = overhead.private_methods
|
751
|
-
(after - before).should_not == []
|
752
|
-
aspect1.unadvise
|
753
|
-
after = overhead.private_methods
|
754
|
-
(after - before).should_not == []
|
755
|
-
aspect2.unadvise
|
756
|
-
after = overhead.private_methods
|
757
|
-
(after - before).should == []
|
758
777
|
end
|
759
778
|
end
|
760
779
|
|
@@ -275,7 +275,7 @@ describe Aquarium::Aspects::JoinPoint, "#invoke_original_join_point" do
|
|
275
275
|
:advice_kind => :around,
|
276
276
|
:advised_object => ioc,
|
277
277
|
:parameters => [],
|
278
|
-
:
|
278
|
+
:current_advice_node => Aquarium::Aspects::NoAdviceChainNode.new({:alias_method_name => :invoke})
|
279
279
|
}
|
280
280
|
jp2 = jp.make_current_context_join_point context_opts
|
281
281
|
jp2.invoke_original_join_point
|
@@ -300,13 +300,13 @@ describe Pointcut, "methods" do
|
|
300
300
|
pc.join_points_not_matched.should == @expected_modules_not_matched_jps
|
301
301
|
end
|
302
302
|
|
303
|
-
Aspect::CANONICAL_OPTIONS["types_and_ancestors"].each do |key|
|
303
|
+
Aspect::CANONICAL_OPTIONS["types_and_ancestors"].reject{|key| key.eql?("types_and_ancestors")}.each do |key|
|
304
304
|
it "should accept :#{key} as a synonym for :types_and_ancestors." do
|
305
305
|
lambda {Pointcut.new key.intern => /^Module.*Method/, :methods => :all, :noop => true}.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
306
306
|
end
|
307
307
|
end
|
308
308
|
|
309
|
-
Aspect::CANONICAL_OPTIONS["types_and_descendents"].each do |key|
|
309
|
+
Aspect::CANONICAL_OPTIONS["types_and_descendents"].reject{|key| key.eql?("types_and_descendents")}.each do |key|
|
310
310
|
it "should accept :#{key} as a synonym for :types_and_descendents." do
|
311
311
|
lambda {Pointcut.new key.intern => /^Module.*Method/, :methods => :all, :noop => true}.should_not raise_error(Aquarium::Utils::InvalidOptions)
|
312
312
|
end
|
@@ -342,7 +342,7 @@ describe Pointcut, "methods" do
|
|
342
342
|
JoinPoint.new(:object => pub, :method_name => :public_instance_test_method)])
|
343
343
|
end
|
344
344
|
|
345
|
-
Aspect::CANONICAL_OPTIONS["objects"].each do |key|
|
345
|
+
Aspect::CANONICAL_OPTIONS["objects"].reject{|key| key.eql?("objects")}.each do |key|
|
346
346
|
it "should accept :#{key} as a synonym for :objects." do
|
347
347
|
pub, pro = ClassWithPublicInstanceMethod.new, ClassWithProtectedInstanceMethod.new
|
348
348
|
pc = Pointcut.new key.intern => [pub, pro], :methods => :all, :method_options => [:public, :protected, :exclude_ancestor_methods]
|
@@ -448,7 +448,7 @@ describe Pointcut, "methods" do
|
|
448
448
|
pc.join_points_not_matched.size.should == 0
|
449
449
|
end
|
450
450
|
|
451
|
-
Aspect::CANONICAL_OPTIONS["exclude_types"].each do |key|
|
451
|
+
Aspect::CANONICAL_OPTIONS["exclude_types"].reject{|key| key.eql?("exclude_types")}.each do |key|
|
452
452
|
it "should accept :#{key} as a synonym for :exclude_types." do
|
453
453
|
pc = Pointcut.new :types => /ExcludeTest/, key.intern => [ExcludeTestTwo, ExcludeTestThree], :method_options => :exclude_ancestor_methods
|
454
454
|
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
@@ -575,6 +575,18 @@ describe Pointcut, "methods" do
|
|
575
575
|
:exclude_types_and_descendents => ClassIncludingModuleWithPublicInstanceMethod, :methods => :all, :method_options => :exclude_ancestor_methods
|
576
576
|
check_class_descendents pc
|
577
577
|
end
|
578
|
+
|
579
|
+
Aspect::CANONICAL_OPTIONS["exclude_types_and_descendents"].reject{|key| key.eql?("exclude_types_and_descendents")}.each do |key|
|
580
|
+
it "should accept :#{key} as a synonym for :exclude_types_and_descendents." do
|
581
|
+
lambda {Pointcut.new :types => /ExcludeTest/, key.intern => [ExcludeTestTwo, ExcludeTestThree], :method_options => :exclude_ancestor_methods, :noop => true}.should_not raise_error
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
Aspect::CANONICAL_OPTIONS["exclude_types_and_ancestors"].reject{|key| key.eql?("exclude_types_and_ancestors")}.each do |key|
|
586
|
+
it "should accept :#{key} as a synonym for :exclude_types_and_ancestors." do
|
587
|
+
lambda {Pointcut.new :types => /ExcludeTest/, key.intern => [ExcludeTestTwo, ExcludeTestThree], :method_options => :exclude_ancestor_methods, :noop => true}.should_not raise_error
|
588
|
+
end
|
589
|
+
end
|
578
590
|
end
|
579
591
|
|
580
592
|
describe Pointcut, ".new (:exclude_objects => objects specified)" do
|
@@ -615,7 +627,7 @@ describe Pointcut, "methods" do
|
|
615
627
|
pc.join_points_not_matched.size.should == 0
|
616
628
|
end
|
617
629
|
|
618
|
-
Aspect::CANONICAL_OPTIONS["exclude_objects"].each do |key|
|
630
|
+
Aspect::CANONICAL_OPTIONS["exclude_objects"].reject{|key| key.eql?("exclude_objects")}.each do |key|
|
619
631
|
it "should accept :#{key} as a synonym for :exclude_objects." do
|
620
632
|
pc = Pointcut.new :objects => @objects, key.intern => @e22, :method_options => :exclude_ancestor_methods
|
621
633
|
actual = pc.join_points_matched.collect {|jp| jp.type_or_object}.uniq
|
@@ -661,7 +673,7 @@ describe Pointcut, "methods" do
|
|
661
673
|
pc.join_points_not_matched.size.should == 0
|
662
674
|
end
|
663
675
|
|
664
|
-
Aspect::CANONICAL_OPTIONS["exclude_join_points"].each do |key|
|
676
|
+
Aspect::CANONICAL_OPTIONS["exclude_join_points"].reject{|key| key.eql?("exclude_join_points")}.each do |key|
|
665
677
|
it "should accept :#{key} as a synonym for :exclude_join_points." do
|
666
678
|
excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
|
667
679
|
expected = [@jp11, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @ojp12, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33]
|
@@ -718,7 +730,7 @@ describe Pointcut, "methods" do
|
|
718
730
|
pc.join_points_not_matched.size.should == 0
|
719
731
|
end
|
720
732
|
|
721
|
-
Aspect::CANONICAL_OPTIONS["exclude_pointcuts"].each do |key|
|
733
|
+
Aspect::CANONICAL_OPTIONS["exclude_pointcuts"].reject{|key| key.eql?("exclude_pointcuts")}.each do |key|
|
722
734
|
it "should accept :#{key} as a synonym for :exclude_pointcuts." do
|
723
735
|
excluded_jps = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
|
724
736
|
excluded = Pointcut.new :join_points => excluded_jps
|
@@ -735,7 +747,7 @@ describe Pointcut, "methods" do
|
|
735
747
|
before_pointcut_class_spec
|
736
748
|
end
|
737
749
|
|
738
|
-
Aspect::CANONICAL_OPTIONS["method_options"].each do |key|
|
750
|
+
Aspect::CANONICAL_OPTIONS["method_options"].reject{|key| key.eql?("method_options")}.each do |key|
|
739
751
|
it "should accept :#{key} as a synonym for :method_options." do
|
740
752
|
pc = Pointcut.new :types => ClassWithPublicInstanceMethod, key.intern => [:public, :instance, :exclude_ancestor_methods]
|
741
753
|
pc.join_points_matched.should be_eql(Set.new([@pub_jp]))
|
@@ -888,7 +900,7 @@ describe Pointcut, "methods" do
|
|
888
900
|
@expected_for_objects = Set.new([@jp_rw_o, @jp_rwe_o, @jp_r_o, @jp_we_o])
|
889
901
|
end
|
890
902
|
|
891
|
-
Aspect::CANONICAL_OPTIONS["methods"].each do |key|
|
903
|
+
Aspect::CANONICAL_OPTIONS["methods"].reject{|key| key.eql?("methods")}.each do |key|
|
892
904
|
it "should accept :#{key} as a synonym for :methods." do
|
893
905
|
pc = Pointcut.new :types => "ClassWithAttribs", key.intern => [/^attr/]
|
894
906
|
pc.join_points_matched.should == @expected_for_types
|
@@ -943,7 +955,7 @@ describe Pointcut, "methods" do
|
|
943
955
|
pc.join_points_not_matched.size.should == 0
|
944
956
|
end
|
945
957
|
|
946
|
-
Aspect::CANONICAL_OPTIONS["exclude_methods"].each do |key|
|
958
|
+
Aspect::CANONICAL_OPTIONS["exclude_methods"].reject{|key| key.eql?("exclude_methods")}.each do |key|
|
947
959
|
it "should accept :#{key} as a synonym for :exclude_methods." do
|
948
960
|
pc = Pointcut.new :join_points => @all_jps, key.intern => /method[12][13]/, :method_options => :exclude_ancestor_methods
|
949
961
|
pc.join_points_matched.size.should == 10
|
@@ -324,9 +324,10 @@ describe Aquarium::Finders::MethodFinder, "#find (searching for class methods)"
|
|
324
324
|
end
|
325
325
|
|
326
326
|
it "should find all class methods specified by regular expression for types when :class is used." do
|
327
|
-
#
|
327
|
+
# NOTE: The list of methods defined by Kernel is different for MRI and JRuby!
|
328
328
|
expected = {}
|
329
|
-
expected[Kernel] = [:
|
329
|
+
expected[Kernel] = [:respond_to?]
|
330
|
+
expected[Kernel] += [:chomp!, :chop!] unless Object.const_defined?('JRUBY_VERSION')
|
330
331
|
[Object, Module, Class].each do |clazz|
|
331
332
|
expected[clazz] = [:respond_to?]
|
332
333
|
end
|
@@ -54,7 +54,7 @@ describe Aquarium::Finders::TypeFinder, "#find invocation parameters" do
|
|
54
54
|
|
55
55
|
it "should accept a hash and treat it as equivalent to an explicit list parameters." do
|
56
56
|
expected_found_types = [Outside::Inside1, Outside::Inside2]
|
57
|
-
expected_unfound_exps = %w[
|
57
|
+
expected_unfound_exps = %w[NonExistent::SubNonExistent::SubSubNonExistent]
|
58
58
|
hash = {:names => (expected_found_types.map {|t| t.to_s} + expected_unfound_exps)}
|
59
59
|
actual = Aquarium::Finders::TypeFinder.new.find hash
|
60
60
|
actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
|
@@ -117,7 +117,7 @@ describe Aquarium::Finders::TypeFinder, "#find with :types, :names, :type, and :
|
|
117
117
|
|
118
118
|
it "should find types with :: namespace delimiters using their names." do
|
119
119
|
expected_found_types = [Outside::Inside1, Outside::Inside2]
|
120
|
-
expected_unfound_exps = %w[
|
120
|
+
expected_unfound_exps = %w[NonExistent::SubNonExistent::SubSubNonExistent]
|
121
121
|
actual = Aquarium::Finders::TypeFinder.new.find :names => (expected_found_types.map {|t| t.to_s} + expected_unfound_exps)
|
122
122
|
actual.matched_keys.sort_by {|x| x.to_s}.should == expected_found_types.sort_by {|x| x.to_s}
|
123
123
|
actual.not_matched_keys.sort.should == expected_unfound_exps.sort
|
@@ -11,7 +11,7 @@ def purge_actuals actuals
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "#find types and their descendents, using :types_and_descendents" do
|
14
|
+
describe TypeUtils, "#find types and their descendents, using :types_and_descendents" do
|
15
15
|
it "should find the matching types and their descendent subclasses, even in different nested modules." do
|
16
16
|
TypeUtils.sample_types.each do |t|
|
17
17
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_descendents => (t.name)
|
@@ -28,7 +28,7 @@ describe "#find types and their descendents, using :types_and_descendents" do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe "#find types subtracting out excluded types and descendents, using :exclude_types_and_descendents" do
|
31
|
+
describe TypeUtils, "#find types subtracting out excluded types and descendents, using :exclude_types_and_descendents" do
|
32
32
|
it "should find the matching types and their descendent subclasses, minus the excluded type hierarchies." do
|
33
33
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_descendents => ModuleForDescendents, :exclude_types_and_descendents => D1ForDescendents
|
34
34
|
actual_keys = purge_actuals actual
|
@@ -47,7 +47,7 @@ describe "#find types subtracting out excluded types and descendents, using :exc
|
|
47
47
|
end
|
48
48
|
|
49
49
|
|
50
|
-
describe "#find types and their ancestors, using :types_and_ancestors" do
|
50
|
+
describe TypeUtils, "#find types and their ancestors, using :types_and_ancestors" do
|
51
51
|
it "should find the matching types and their ancestors, even in different nested modules." do
|
52
52
|
TypeUtils.sample_types.each do |t|
|
53
53
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => (t.name)
|
@@ -65,7 +65,7 @@ describe "#find types and their ancestors, using :types_and_ancestors" do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
|
68
|
-
describe "#find types subtracting out excluded types and ancestors, using :exclude_types_and_ancestors" do
|
68
|
+
describe TypeUtils, "#find types subtracting out excluded types and ancestors, using :exclude_types_and_ancestors" do
|
69
69
|
it "should find the matching types and their ancestors, minus the excluded types and ancestors." do
|
70
70
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => D1ForDescendents, :exclude_types_and_ancestors => ModuleForDescendents
|
71
71
|
actual_keys = purge_actuals actual
|
@@ -84,7 +84,7 @@ describe "#find types subtracting out excluded types and ancestors, using :exclu
|
|
84
84
|
end
|
85
85
|
|
86
86
|
|
87
|
-
describe "#find types and their descendents and ancestors" do
|
87
|
+
describe TypeUtils, "#find types and their descendents and ancestors" do
|
88
88
|
it "should find the matching types and their descendents and ancestors, even in different nested modules." do
|
89
89
|
TypeUtils.sample_types.each do |t|
|
90
90
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => (t.name), :types_and_descendents => (t.name)
|
@@ -96,7 +96,7 @@ describe "#find types and their descendents and ancestors" do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe "#find types subtracting out excluded types and their descendents and ancestors" do
|
99
|
+
describe TypeUtils, "#find types subtracting out excluded types and their descendents and ancestors" do
|
100
100
|
it "should find the matching types and their descendents and ancestors, minus the excluded types and their descendents and ancestors." do
|
101
101
|
actual = Aquarium::Finders::TypeFinder.new.find \
|
102
102
|
:types_and_ancestors => Aquarium::ForDescendents::NestedD1ForDescendents,
|
@@ -110,7 +110,7 @@ describe "#find types subtracting out excluded types and their descendents and a
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
describe "#find types and their descendents and ancestors, specified with regular expressions" do
|
113
|
+
describe TypeUtils, "#find types and their descendents and ancestors, specified with regular expressions" do
|
114
114
|
it "should find the matching types and their descendents and ancestors, even in different nested modules." do
|
115
115
|
regexs = [/ForDescendents$/, /Aquarium::ForDescendents::.*ForDescendents/]
|
116
116
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => regexs, :types_and_descendents => regexs
|
@@ -125,7 +125,7 @@ describe "#find types and their descendents and ancestors, specified with regula
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
describe "#find types and their descendents and ancestors, subtracting out excluded types and their descendents and ancestors, specified using regular expressions" do
|
128
|
+
describe TypeUtils, "#find types and their descendents and ancestors, subtracting out excluded types and their descendents and ancestors, specified using regular expressions" do
|
129
129
|
it "should find the matching types and their descendents and ancestors, minus the excluded types and their descendents and ancestors." do
|
130
130
|
actual = Aquarium::Finders::TypeFinder.new.find :types_and_ancestors => /Aquarium::ForDescendents::.*D1ForDescendents/,
|
131
131
|
:types_and_descendents => /Aquarium::ForDescendents::.*D1ForDescendents/,
|
@@ -162,10 +162,19 @@ describe Aquarium::Utils::MethodUtils, ".visibility" do
|
|
162
162
|
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_instance_m, :instance_method_only).should == :private
|
163
163
|
end
|
164
164
|
|
165
|
-
it "should ignore whether the exclude_ancestors flag is true or false for class methods" do
|
166
|
-
|
167
|
-
|
165
|
+
it "should ignore whether the exclude_ancestors flag is true or false for class methods when running under MRI" do
|
166
|
+
unless Object.const_defined?('JRUBY_VERSION')
|
167
|
+
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :public_class_m, :class_method_only, false).should == :public
|
168
|
+
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :private_class_m, :class_method_only, false).should == :private
|
169
|
+
end
|
170
|
+
end
|
171
|
+
it "should NOT ignore whether the exclude_ancestors flag is true or false for class methods when running under JRuby" do
|
172
|
+
if Object.const_defined?('JRUBY_VERSION')
|
173
|
+
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :public_class_m, :class_method_only, false).should == nil
|
174
|
+
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :private_class_m, :class_method_only, false).should == nil
|
175
|
+
end
|
168
176
|
end
|
177
|
+
|
169
178
|
it "should return nil for public instance methods on a subclass when the exclude_ancestors flag is false" do
|
170
179
|
Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :public_instance_m, :instance_method_only, false).should == nil
|
171
180
|
end
|
@@ -288,10 +297,12 @@ describe Aquarium::Utils::MethodUtils, ".has_method" do
|
|
288
297
|
Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_instance_m, :instance_method_only).should be_true
|
289
298
|
end
|
290
299
|
|
291
|
-
|
292
|
-
|
293
|
-
Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :
|
300
|
+
not_string, true_or_false, ruby_name = Object.const_defined?('JRUBY_VERSION') ? ['NOT ', false, 'JRuby'] : ['', true, 'MRI']
|
301
|
+
it "should #{not_string}ignore whether the exclude_ancestors flag is true or false for class methods when running under #{ruby_name}" do
|
302
|
+
Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :public_class_m, :class_method_only, false).should == true_or_false
|
303
|
+
Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :private_class_m, :class_method_only, false).should == true_or_false
|
294
304
|
end
|
305
|
+
|
295
306
|
it "should return false for public instance methods on a subclass when the exclude_ancestors flag is false" do
|
296
307
|
Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :public_instance_m, :instance_method_only, false).should be_false
|
297
308
|
end
|