aquarium 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,14 @@ describe "Advising an object join point and then the corresponding type join poi
20
20
  @aspects = []
21
21
  @invoked = []
22
22
  @accessed = ConcurrentlyAccessed.new
23
+ @accessed2 = ConcurrentlyAccessed.new
23
24
  end
24
25
  after :each do
25
26
  @aspects.each {|a| a.unadvise}
26
27
  end
27
28
 
28
29
  Aquarium::Aspects::Advice.kinds.each do |advice_kind|
29
- it "should invoke only the advice on the object join point for :#{advice_kind} advice" do
30
+ it "should invoke both the :#{advice_kind} advices when the object join point is invoked" do
30
31
  method = advice_kind == :after_raising ? :invoke_raises : :invoke
31
32
  @aspects << make_aspect(method, advice_kind, :object, @accessed)
32
33
  @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
@@ -36,7 +37,22 @@ describe "Advising an object join point and then the corresponding type join poi
36
37
  rescue ConcurrentlyAccessed::Error
37
38
  fail unless advice_kind == :after_raising
38
39
  end
39
- @invoked.should == [:object]
40
+ @invoked.sort.should == [:object, :type]
41
+ end
42
+ end
43
+
44
+ Aquarium::Aspects::Advice.kinds.each do |advice_kind|
45
+ it "should invoke only the :#{advice_kind} type advice when a different object is invoked" do
46
+ method = advice_kind == :after_raising ? :invoke_raises : :invoke
47
+ @aspects << make_aspect(method, advice_kind, :object, @accessed2)
48
+ @aspects << make_aspect(method, advice_kind, :type, ConcurrentlyAccessed)
49
+ begin
50
+ @accessed.method(method).call :a1, :a2
51
+ fail if advice_kind == :after_raising
52
+ rescue ConcurrentlyAccessed::Error
53
+ fail unless advice_kind == :after_raising
54
+ end
55
+ @invoked.should == [:type]
40
56
  end
41
57
  end
42
58
  end
@@ -265,14 +265,56 @@ describe Aquarium::Aspects::JoinPoint, "#<=>" do
265
265
  @jp3 = Aquarium::Aspects::JoinPoint.new :type => Array, :method_name => :size
266
266
  @jp4 = Aquarium::Aspects::JoinPoint.new :object => [], :method_name => :size
267
267
  @jp5 = Aquarium::Aspects::JoinPoint.new :object => [], :method_name => :size
268
+ dummy = Dummy.new
269
+ @jp6 = Aquarium::Aspects::JoinPoint.new :object => dummy, :method_name => :size
270
+ @jp7 = Aquarium::Aspects::JoinPoint.new :object => dummy, :method_name => :size
271
+ context_opts = {
272
+ :advice_kind => :before,
273
+ :advised_object => dummy,
274
+ :parameters => [],
275
+ :block_for_method => nil,
276
+ :returned_value => nil,
277
+ :raised_exception => nil,
278
+ :proceed_proc => nil
279
+ }
280
+ @jp1b = @jp1.make_current_context_join_point context_opts
281
+ @jp2b = @jp2.make_current_context_join_point context_opts
282
+ @jp6b = @jp6.make_current_context_join_point context_opts
283
+ @jp7b = @jp7.make_current_context_join_point context_opts
268
284
  end
269
285
 
270
- it "should sort return 0 for the same join points" do
271
- (@jp1.<=>@jp1).should == 0
286
+ it "should return 1 of the second object is nil" do
287
+ (@jp1 <=> nil).should == 1
272
288
  end
273
289
 
274
- it "should sort return 0 for equivalent join points" do
275
- (@jp1.<=>@jp2).should == 0
290
+ it "should return 0 for the same join point with no context" do
291
+ (@jp1 <=> @jp1).should == 0
292
+ (@jp6 <=> @jp6).should == 0
293
+ end
294
+
295
+ it "should return 0 for the same join point with equivalent contexts" do
296
+ (@jp1b <=> @jp1b).should == 0
297
+ (@jp6b <=> @jp6b).should == 0
298
+ end
299
+
300
+ it "should return 0 for equivalent join points with no context" do
301
+ (@jp1 <=>@jp2).should == 0
302
+ (@jp6 <=>@jp7).should == 0
303
+ end
304
+
305
+ it "should return 0 for equivalent join points with equivalent contexts" do
306
+ (@jp1b <=> @jp2b).should == 0
307
+ (@jp6b <=> @jp7b).should == 0
308
+ end
309
+
310
+ it "should return +1 for join points that equivalent except for the context, where the first join point has a context and the second does not" do
311
+ (@jp1b <=> @jp2).should == 1
312
+ (@jp6b <=> @jp7).should == 1
313
+ end
314
+
315
+ it "should return -1 for join points that equivalent except for the context, where the second join point has a context and the first does not" do
316
+ (@jp1 <=> @jp2b).should == -1
317
+ (@jp6 <=> @jp6b).should == -1
276
318
  end
277
319
 
278
320
  it "should sort by type name first" do
@@ -6,22 +6,6 @@ require 'aquarium/aspects/join_point'
6
6
  require 'aquarium/aspects/pointcut'
7
7
  require 'aquarium/utils'
8
8
 
9
- class ExcludeTestOne
10
- def method11; end
11
- def method12; end
12
- def method13; end
13
- end
14
- class ExcludeTestTwo
15
- def method21; end
16
- def method22; end
17
- def method23; end
18
- end
19
- class ExcludeTestThree
20
- def method31; end
21
- def method32; end
22
- def method33; end
23
- end
24
-
25
9
  def before_exclude_spec
26
10
  @jp11 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method11
27
11
  @jp12 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method12
@@ -371,28 +355,25 @@ describe Aquarium::Aspects::Pointcut, " (:exclude_join_points => join_points spe
371
355
 
372
356
  it "should remove from a list of explicitly-specified join points the set of explicitly-specified excluded join points." do
373
357
  excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
358
+ expected = [@jp11, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @ojp12, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33]
374
359
  pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_join_points => excluded
375
- pc.join_points_matched.should == Set.new(@all_jps - excluded)
360
+ pc.join_points_matched.should == Set.new(expected)
376
361
  pc.join_points_not_matched.size.should == 0
377
362
  end
378
363
 
379
364
  it "should remove from the list of generated, type-based join points the set of explicitly-specified excluded join points." do
380
- jp11 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestOne, :method_name => :method11
381
- jp22 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestTwo, :method_name => :method22
382
- jp33 = Aquarium::Aspects::JoinPoint.new :type => ExcludeTestThree, :method_name => :method33
383
- excluded = [jp11, jp22, jp33]
365
+ excluded = [@jp11, @jp22, @jp33]
366
+ expected = [@jp12, @jp13, @jp21, @jp23, @jp31, @jp32]
384
367
  pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_join_points => excluded, :method_options => :exclude_ancestor_methods
385
- pc.join_points_matched.should == Set.new(@all_type_jps - excluded)
368
+ pc.join_points_matched.should == Set.new(expected)
386
369
  pc.join_points_not_matched.size.should == 0
387
370
  end
388
371
 
389
372
  it "should remove from the list of generated, object-based join points the set of explicitly-specified excluded join points." do
390
- ojp12 = Aquarium::Aspects::JoinPoint.new :object => @et1, :method_name => :method12
391
- ojp23 = Aquarium::Aspects::JoinPoint.new :object => @et2, :method_name => :method23
392
- ojp31 = Aquarium::Aspects::JoinPoint.new :object => @et3, :method_name => :method31
393
- excluded = [ojp12, ojp23, ojp31]
373
+ excluded = [@ojp12, @ojp23, @ojp31]
374
+ expected = [@ojp11, @ojp13, @ojp21, @ojp22, @ojp32, @ojp33]
394
375
  pc = Aquarium::Aspects::Pointcut.new :objects => [@et1, @et2, @et3], :exclude_join_points => excluded, :method_options => :exclude_ancestor_methods
395
- pc.join_points_matched.should == Set.new(@all_object_jps - excluded)
376
+ pc.join_points_matched.should == Set.new(expected)
396
377
  pc.join_points_not_matched.size.should == 0
397
378
  end
398
379
 
@@ -404,8 +385,66 @@ describe Aquarium::Aspects::Pointcut, " (:exclude_join_points => join_points spe
404
385
 
405
386
  it "should be a synonym for :exclude_join_point." do
406
387
  excluded = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
388
+ expected = [@jp11, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @ojp12, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33]
407
389
  pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_join_point => excluded
408
- pc.join_points_matched.should == Set.new(@all_jps - excluded)
390
+ pc.join_points_matched.should == Set.new(expected)
391
+ pc.join_points_not_matched.size.should == 0
392
+ end
393
+ end
394
+
395
+
396
+ describe Aquarium::Aspects::Pointcut, " (:exclude_pointcuts => pointcuts specified)" do
397
+ before(:each) do
398
+ before_exclude_spec
399
+ end
400
+
401
+ it "should remove from a list of explicitly-specified join points the set of explicitly-specified excluded pointcuts." do
402
+ excluded_jps = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
403
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => excluded_jps
404
+ expected = [@jp11, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @ojp12, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33]
405
+ pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_pointcuts => excluded
406
+ pc.join_points_matched.should == Set.new(expected)
407
+ pc.join_points_not_matched.size.should == 0
408
+ end
409
+
410
+ it "should remove from the list of generated, type-based join points the set of explicitly-specified excluded pointcuts." do
411
+ excluded_jps = [@jp11, @jp22, @jp33]
412
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => excluded_jps
413
+ expected = [@jp12, @jp13, @jp21, @jp23, @jp31, @jp32]
414
+ pc = Aquarium::Aspects::Pointcut.new :types => /ExcludeTest/, :exclude_pointcuts => excluded, :method_options => :exclude_ancestor_methods
415
+ pc.join_points_matched.should == Set.new(expected)
416
+ pc.join_points_not_matched.size.should == 0
417
+ end
418
+
419
+ it "should remove from the list of generated, object-based join points the set of explicitly-specified excluded pointcuts." do
420
+ excluded_jps = [@ojp12, @ojp23, @ojp31]
421
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => excluded_jps
422
+ expected = [@ojp11, @ojp13, @ojp21, @ojp22, @ojp32, @ojp33]
423
+ pc = Aquarium::Aspects::Pointcut.new :objects => [@et1, @et2, @et3], :exclude_pointcuts => excluded, :method_options => :exclude_ancestor_methods
424
+ pc.join_points_matched.should == Set.new(expected)
425
+ pc.join_points_not_matched.size.should == 0
426
+ end
427
+
428
+ it "should not add excluded types to the #not_matched results." do
429
+ excluded_jps = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
430
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => excluded_jps
431
+ pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_pointcuts => excluded
432
+ pc.join_points_not_matched.size.should == 0
433
+ end
434
+
435
+ it "should result in an empty pointcut if the join points in the :exclude_pointcuts are a superset of the matched join points." do
436
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => @all_jps
437
+ pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_pointcut => excluded
438
+ pc.join_points_matched.size.should == 0
439
+ pc.join_points_not_matched.size.should == 0
440
+ end
441
+
442
+ it "should be a synonym for :exclude_pointcut." do
443
+ excluded_jps = [@jp12, @jp33, @ojp11, @ojp13, @ojp23]
444
+ excluded = Aquarium::Aspects::Pointcut.new :join_points => excluded_jps
445
+ expected = [@jp11, @jp13, @jp21, @jp22, @jp23, @jp31, @jp32, @ojp12, @ojp21, @ojp22, @ojp31, @ojp32, @ojp33]
446
+ pc = Aquarium::Aspects::Pointcut.new :join_points => @all_jps, :exclude_pointcut => excluded
447
+ pc.join_points_matched.should == Set.new(expected)
409
448
  pc.join_points_not_matched.size.should == 0
410
449
  end
411
450
  end
@@ -898,7 +937,7 @@ describe Aquarium::Aspects::Pointcut, "#eql?" do
898
937
  pc1.should be_eql(pc2)
899
938
  end
900
939
 
901
- it "should return false for Aquarium::Aspects::Pointcuts that specify different types." do
940
+ it "should return false if the matched types are different." do
902
941
  pc1 = Aquarium::Aspects::Pointcut.new :types => /ClassWithPublicMethod/
903
942
  pc2 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/
904
943
  pc1.should_not eql(pc2)
@@ -928,18 +967,19 @@ describe Aquarium::Aspects::Pointcut, "#eql?" do
928
967
  pc1.should_not eql(pc2)
929
968
  end
930
969
 
931
- it "should return false if the matched types are different." do
932
- pc1 = Aquarium::Aspects::Pointcut.new :types => /ClassWithPublicMethod/
933
- pc2 = Aquarium::Aspects::Pointcut.new :types => /Class.*Method/
934
- pc1.should_not eql(pc2)
935
- end
936
-
937
- it "should return false if the matched objects are different." do
970
+ it "should return false if the matched objects are different objects." do
938
971
  pc1 = Aquarium::Aspects::Pointcut.new :object => ClassWithPublicClassMethod.new, :methods => /_test_method$/
939
972
  pc2 = Aquarium::Aspects::Pointcut.new :object => ClassWithPrivateClassMethod.new, :methods => /_test_method$/
940
973
  pc1.should_not eql(pc2)
941
974
  end
942
975
 
976
+ it "should return true if the matched objects are the same object." do
977
+ object = ClassWithPublicClassMethod.new
978
+ pc1 = Aquarium::Aspects::Pointcut.new :object => object, :methods => /_test_method$/
979
+ pc2 = Aquarium::Aspects::Pointcut.new :object => object, :methods => /_test_method$/
980
+ pc1.should eql(pc2)
981
+ end
982
+
943
983
  it "should return false if the not_matched types are different." do
944
984
  pc1 = Aquarium::Aspects::Pointcut.new :types => :UnknownFoo
945
985
  pc2 = Aquarium::Aspects::Pointcut.new :types => :UnknownBar
@@ -1100,8 +1140,9 @@ describe Aquarium::Aspects::Pointcut, "#specification" do
1100
1140
  :exclude_types => @empty_set,
1101
1141
  :exclude_objects => @empty_set,
1102
1142
  :exclude_join_points => @empty_set,
1143
+ :exclude_pointcuts => @empty_set,
1103
1144
  :exclude_methods => @empty_set,
1104
- :default_object => @empty_set}
1145
+ :default_objects => @empty_set}
1105
1146
  @default_specification_all_methods = { :methods => Set.new([:all]) } | @default_specification
1106
1147
  end
1107
1148
 
@@ -1130,13 +1171,13 @@ describe Aquarium::Aspects::Pointcut, "#specification" do
1130
1171
  it "should return the input :method_options verbatim." do
1131
1172
  pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :methods => /^get/, :method => "dup", :method_options => [:instance, :public]
1132
1173
  pc.specification.should == { :types => Set.new(@example_types), :methods => Set.new([/^get/, "dup"]),
1133
- :method_options => Set.new([:instance, :public]), :default_object => @empty_set } | @default_specification
1174
+ :method_options => Set.new([:instance, :public]), :default_objects => @empty_set } | @default_specification
1134
1175
  end
1135
1176
 
1136
1177
  it "should return the input :methods and :method arguments combined into an array keyed by :methods." do
1137
1178
  pc = Aquarium::Aspects::Pointcut.new :types => @example_types, :attributes => /^state/, :attribute => "name"
1138
1179
  pc.specification.should == { :types => Set.new(@example_types), :objects => @empty_set, :join_points => @empty_set,
1139
- :methods => @empty_set, :method_options => Set.new([]), :default_object => @empty_set,
1180
+ :methods => @empty_set, :method_options => Set.new([]), :default_objects => @empty_set,
1140
1181
  :attributes => Set.new([/^state/, "name"]), :attribute_options => @empty_set } | @default_specification
1141
1182
  end
1142
1183
 
@@ -294,6 +294,12 @@ describe Aquarium::Finders::MethodFinder, "#find (searching for instance methods
294
294
  actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test_method/
295
295
  actual.matched.size.should == 1
296
296
  actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
297
+ actual2 = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test/
298
+ actual2.matched.size.should == 1
299
+ actual2.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
300
+ actual3 = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /test_method/
301
+ actual3.matched.size.should == 1
302
+ actual3.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
297
303
  end
298
304
 
299
305
  it "should find only one instance method for an object when searching with a regexp matching one method." do
@@ -443,7 +449,15 @@ describe Aquarium::Finders::MethodFinder, "#find for types (using :exclude_metho
443
449
  actual.not_matched.size.should == 0
444
450
  end
445
451
 
446
- it "should remove excluded methods from the result where the excluded methods are specified by name." do
452
+ it "should remove excluded methods from the result where a single excluded methods is specified by name." do
453
+ actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_method => :method1, :options => :exclude_ancestor_methods
454
+ actual.matched.size.should == 1
455
+ actual.matched[ExcludeMethodTester].size.should == 2
456
+ actual.matched[ExcludeMethodTester].should == Set.new([:method2, :method3])
457
+ actual.not_matched.size.should == 0
458
+ end
459
+
460
+ it "should remove excluded methods from the result where the excluded methods are specified by an array of names." do
447
461
  actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_methods => [:method1, :method2], :options => :exclude_ancestor_methods
448
462
  actual.matched.size.should == 1
449
463
  actual.matched[ExcludeMethodTester].size.should == 1
@@ -480,7 +494,16 @@ describe Aquarium::Finders::MethodFinder, "#find for objects (using :exclude_met
480
494
  actual.not_matched.size.should == 0
481
495
  end
482
496
 
483
- it "should remove excluded methods from the result where the excluded methods are specified by name." do
497
+ it "should remove excluded methods from the result where a single excluded methods is specified by name." do
498
+ emt = ExcludeMethodTester.new
499
+ actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_method => :method1, :options => :exclude_ancestor_methods
500
+ actual.matched.size.should == 1
501
+ actual.matched[emt].size.should == 2
502
+ actual.matched[emt].should == Set.new([:method2, :method3])
503
+ actual.not_matched.size.should == 0
504
+ end
505
+
506
+ it "should remove excluded methods from the result where the excluded methods are specified by an array of names." do
484
507
  emt = ExcludeMethodTester.new
485
508
  actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_methods => [:method1, :method2], :options => :exclude_ancestor_methods
486
509
  actual.matched.size.should == 1
@@ -289,7 +289,7 @@ describe Aquarium::Finders::TypeFinder, "#find_by_type" do
289
289
  end
290
290
  end
291
291
 
292
- # TODO refactor this protected method into a new class.
292
+ # This is a spec for a protected method.
293
293
  describe Aquarium::Finders::TypeFinder, "#get_type_from_parent should" do
294
294
  it "should raise if a type doesn't exist that matches the constant" do
295
295
  lambda {Aquarium::Finders::TypeFinder.new.send(:get_type_from_parent, Aquarium::Finders, "Nonexistent", /Non/)}.should raise_error(NameError)
@@ -119,3 +119,20 @@ class Watchful
119
119
  end
120
120
 
121
121
  class WatchfulChild < Watchful; end
122
+
123
+ class ExcludeTestOne
124
+ def method11; end
125
+ def method12; end
126
+ def method13; end
127
+ end
128
+ class ExcludeTestTwo
129
+ def method21; end
130
+ def method22; end
131
+ def method23; end
132
+ end
133
+ class ExcludeTestThree
134
+ def method31; end
135
+ def method32; end
136
+ def method33; end
137
+ end
138
+
@@ -45,129 +45,353 @@ describe Aquarium::Utils::MethodUtils, ".method_args_to_hash" do
45
45
 
46
46
  it "should return a hash with the non-hash arguments mapped to key-value pairs with value specified by the input block (or null) and the input unchanged." do
47
47
  Aquarium::Utils::MethodUtils.method_args_to_hash(:x, :y, :a =>'a', :b => 'b'){|a| a.to_s.capitalize}.should == {:a => 'a', :b => 'b', :x => 'X', :y => 'Y'}
48
- end
49
-
48
+ end
49
+ end
50
+
51
+ class MethodUtilsSpecProtectionExample
52
+ def public_instance_m; end
53
+ protected
54
+ def protected_instance_m; end
55
+ private
56
+ def private_instance_m; end
57
+ def self.public_class_m; end
58
+ def self.private_class_m; end
59
+ private_class_method :private_class_m
60
+ end
61
+ class MethodUtilsSpecProtectionExample2 < MethodUtilsSpecProtectionExample
50
62
  end
51
63
 
52
64
  describe Aquarium::Utils::MethodUtils, ".visibility" do
53
- class ProtectionExample
54
- def public_instance_m; end
55
- protected
56
- def protected_instance_m; end
57
- private
58
- def private_instance_m; end
59
- def self.public_class_m; end
60
- def self.private_class_m; end
61
- private_class_method :private_class_m
62
- end
63
-
64
65
  it "should return :public for public class methods on a class" do
65
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m).should == :public
66
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_class_m).should == :public
66
67
  end
67
68
  it "should return :public for public class methods on a class when only class methods are specified" do
68
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m, :class_method_only).should == :public
69
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_class_m, :class_method_only).should == :public
69
70
  end
70
71
  it "should return nil for public class methods on a class when only instance methods are specified" do
71
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_class_m, :instance_method_only).should == nil
72
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_class_m, :instance_method_only).should be_nil
72
73
  end
73
74
 
74
75
  it "should return :public for public instance methods on a class" do
75
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m).should == :public
76
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_instance_m).should == :public
76
77
  end
77
78
  it "should return nil for public instance methods on a class when only class methods are specified" do
78
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m, :class_method_only).should == nil
79
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_instance_m, :class_method_only).should be_nil
79
80
  end
80
81
  it "should return :public for public instance methods on a class when only instance methods are specified" do
81
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :public_instance_m, :instance_method_only).should == :public
82
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :public_instance_m, :instance_method_only).should == :public
82
83
  end
83
84
 
84
85
  it "should return nil for public class methods on an instance of a class" do
85
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m).should == nil
86
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_class_m).should be_nil
86
87
  end
87
88
  it "should return nil for public class methods on an instance of a class when only class methods are specified" do
88
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m, :class_method_only).should == nil
89
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_class_m, :class_method_only).should be_nil
89
90
  end
90
91
  it "should return nil for public class methods on an instance of a class when only instance methods are specified" do
91
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_class_m, :instance_method_only).should == nil
92
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_class_m, :instance_method_only).should be_nil
92
93
  end
93
94
 
94
95
  it "should return :public for public instance methods on an instance of a class" do
95
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m).should == :public
96
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_instance_m).should == :public
96
97
  end
97
98
  it "should return nil for public instance methods on an instance of a class when only class methods are specified" do
98
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m, :class_method_only).should == nil
99
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_instance_m, :class_method_only).should be_nil
99
100
  end
100
101
  it "should return :public for public instance methods on an instance of a class when only instance methods are specified" do
101
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :public_instance_m, :instance_method_only).should == :public
102
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :public_instance_m, :instance_method_only).should == :public
102
103
  end
103
104
 
104
105
  it "should return :protected for protected instance methods on a class" do
105
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m).should == :protected
106
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :protected_instance_m).should == :protected
106
107
  end
107
108
  it "should return nil for protected instance methods on a class when only class methods are specified" do
108
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m, :class_method_only).should == nil
109
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :protected_instance_m, :class_method_only).should be_nil
109
110
  end
110
111
  it "should return :protected for protected instance methods on a class when only instance methods are specified" do
111
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :protected_instance_m, :instance_method_only).should == :protected
112
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :protected_instance_m, :instance_method_only).should == :protected
112
113
  end
113
114
 
114
115
  it "should return :protected for protected instance methods on an instance of a class" do
115
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m).should == :protected
116
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :protected_instance_m).should == :protected
116
117
  end
117
118
  it "should return nil for protected instance methods on an instance of a class when only class methods are specified" do
118
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m, :class_method_only).should == nil
119
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :protected_instance_m, :class_method_only).should be_nil
119
120
  end
120
121
  it "should return :protected for protected instance methods on an instance of a class when only instance methods are specified" do
121
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :protected_instance_m, :instance_method_only).should == :protected
122
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :protected_instance_m, :instance_method_only).should == :protected
122
123
  end
123
124
 
124
125
  it "should return :private for private class methods on a class" do
125
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m).should == :private #expected_private
126
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_class_m).should == :private #expected_private
126
127
  end
127
128
  it "should return :private for private class methods on a class when only class methods are specified" do
128
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m, :class_method_only).should == :private #expected_private
129
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_class_m, :class_method_only).should == :private #expected_private
129
130
  end
130
131
  it "should return nil for private class methods on a class when only instance methods are specified" do
131
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_class_m, :instance_method_only).should == nil
132
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_class_m, :instance_method_only).should be_nil
132
133
  end
133
134
 
134
135
  it "should return :private for private instance methods on a class" do
135
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m).should == :private
136
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_instance_m).should == :private
136
137
  end
137
138
  it "should return nil for private instance methods on a class when only class methods are specified" do
138
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m, :class_method_only).should == nil
139
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_instance_m, :class_method_only).should be_nil
139
140
  end
140
141
  it "should return :private for private instance methods on a class when only instance methods are specified" do
141
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample, :private_instance_m, :instance_method_only).should == :private
142
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample, :private_instance_m, :instance_method_only).should == :private
142
143
  end
143
144
 
144
145
  it "should return nil for private class methods on an instance of a class" do
145
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m).should == nil
146
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_class_m).should be_nil
146
147
  end
147
148
  it "should return nil for private class methods on an instance of a class when only class methods are specified" do
148
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m, :class_method_only).should == nil
149
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_class_m, :class_method_only).should be_nil
149
150
  end
150
151
  it "should return nil for private class methods on an instance of a class when only instance methods are specified" do
151
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_class_m, :instance_method_only).should == nil
152
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_class_m, :instance_method_only).should be_nil
152
153
  end
153
154
 
154
155
  it "should return :private for private instance methods on an instance of a class" do
155
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m).should == :private
156
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_instance_m).should == :private
156
157
  end
157
158
  it "should return nil for private instance methods on an instance of a class when only class methods are specified" do
158
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m, :class_method_only).should == nil
159
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_instance_m, :class_method_only).should be_nil
159
160
  end
160
161
  it "should return :private for private instance methods on an instance of a class when only instance methods are specified" do
161
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :private_instance_m, :instance_method_only).should == :private
162
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :private_instance_m, :instance_method_only).should == :private
162
163
  end
163
164
 
165
+ it "should ignore whether the exclude_ancestors flag is true or false for class methods" do
166
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :public_class_m, :class_method_only, false).should == :public
167
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :private_class_m, :class_method_only, false).should == :private
168
+ end
169
+ it "should return nil for public instance methods on a subclass when the exclude_ancestors flag is false" do
170
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :public_instance_m, :instance_method_only, false).should == nil
171
+ end
172
+ it "should return nil for protected instance methods on a subclass when the exclude_ancestors flag is false" do
173
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :protected_instance_m, :instance_method_only, false).should == nil
174
+ end
175
+ it "should return nil for private instance methods on a subclass when the exclude_ancestors flag is false" do
176
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample2, :private_instance_m, :instance_method_only, false).should == nil
177
+ end
178
+
164
179
  it "should return nil for an unknown method" do
165
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method).should == nil
180
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :nonexistent_method).should be_nil
166
181
  end
167
182
  it "should return nil for an unknown method when only class methods are specified" do
168
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method, :class_method_only).should == nil
183
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :nonexistent_method, :class_method_only).should be_nil
169
184
  end
170
185
  it "should return nil for an unknown method when only instance methods are specified" do
171
- Aquarium::Utils::MethodUtils.visibility(ProtectionExample.new, :nonexistent_method, :instance_method_only).should == nil
186
+ Aquarium::Utils::MethodUtils.visibility(MethodUtilsSpecProtectionExample.new, :nonexistent_method, :instance_method_only).should be_nil
187
+ end
188
+ end
189
+
190
+ describe Aquarium::Utils::MethodUtils, ".has_method" do
191
+ it "should return true for public class methods on a class" do
192
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_class_m).should be_true
193
+ end
194
+ it "should return true for public class methods on a class when only class methods are specified" do
195
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_class_m, :class_method_only).should be_true
196
+ end
197
+ it "should return false for public class methods on a class when only instance methods are specified" do
198
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_class_m, :instance_method_only).should be_false
199
+ end
200
+
201
+ it "should return true for public instance methods on a class" do
202
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_instance_m).should be_true
203
+ end
204
+ it "should return false for public instance methods on a class when only class methods are specified" do
205
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_instance_m, :class_method_only).should be_false
206
+ end
207
+ it "should return true for public instance methods on a class when only instance methods are specified" do
208
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :public_instance_m, :instance_method_only).should be_true
209
+ end
210
+
211
+ it "should return false for public class methods on an instance of a class" do
212
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_class_m).should be_false
213
+ end
214
+ it "should return false for public class methods on an instance of a class when only class methods are specified" do
215
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_class_m, :class_method_only).should be_false
216
+ end
217
+ it "should return false for public class methods on an instance of a class when only instance methods are specified" do
218
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_class_m, :instance_method_only).should be_false
219
+ end
220
+
221
+ it "should return true for public instance methods on an instance of a class" do
222
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_instance_m).should be_true
223
+ end
224
+ it "should return false for public instance methods on an instance of a class when only class methods are specified" do
225
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_instance_m, :class_method_only).should be_false
226
+ end
227
+ it "should return true for public instance methods on an instance of a class when only instance methods are specified" do
228
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :public_instance_m, :instance_method_only).should be_true
229
+ end
230
+
231
+ it "should return true for protected instance methods on a class" do
232
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :protected_instance_m).should be_true
233
+ end
234
+ it "should return false for protected instance methods on a class when only class methods are specified" do
235
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :protected_instance_m, :class_method_only).should be_false
236
+ end
237
+ it "should return true for protected instance methods on a class when only instance methods are specified" do
238
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :protected_instance_m, :instance_method_only).should be_true
239
+ end
240
+
241
+ it "should return true for protected instance methods on an instance of a class" do
242
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :protected_instance_m).should be_true
243
+ end
244
+ it "should return false for protected instance methods on an instance of a class when only class methods are specified" do
245
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :protected_instance_m, :class_method_only).should be_false
246
+ end
247
+ it "should return true for protected instance methods on an instance of a class when only instance methods are specified" do
248
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :protected_instance_m, :instance_method_only).should be_true
249
+ end
250
+
251
+ it "should return true for private class methods on a class" do
252
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_class_m).should be_true #expected_private
253
+ end
254
+ it "should return true for private class methods on a class when only class methods are specified" do
255
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_class_m, :class_method_only).should be_true
256
+ end
257
+ it "should return false for private class methods on a class when only instance methods are specified" do
258
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_class_m, :instance_method_only).should be_false
259
+ end
260
+
261
+ it "should return true for private instance methods on a class" do
262
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_instance_m).should be_true
263
+ end
264
+ it "should return false for private instance methods on a class when only class methods are specified" do
265
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_instance_m, :class_method_only).should be_false
266
+ end
267
+ it "should return true for private instance methods on a class when only instance methods are specified" do
268
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample, :private_instance_m, :instance_method_only).should be_true
269
+ end
270
+
271
+ it "should return false for private class methods on an instance of a class" do
272
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_class_m).should be_false
273
+ end
274
+ it "should return false for private class methods on an instance of a class when only class methods are specified" do
275
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_class_m, :class_method_only).should be_false
276
+ end
277
+ it "should return false for private class methods on an instance of a class when only instance methods are specified" do
278
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_class_m, :instance_method_only).should be_false
279
+ end
280
+
281
+ it "should return true for private instance methods on an instance of a class" do
282
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_instance_m).should be_true
283
+ end
284
+ it "should return false for private instance methods on an instance of a class when only class methods are specified" do
285
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_instance_m, :class_method_only).should be_false
286
+ end
287
+ it "should return true for private instance methods on an instance of a class when only instance methods are specified" do
288
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :private_instance_m, :instance_method_only).should be_true
289
+ end
290
+
291
+ it "should ignore whether the exclude_ancestors flag is true or false for class methods" do
292
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :public_class_m, :class_method_only, false).should be_true
293
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :private_class_m, :class_method_only, false).should be_true
294
+ end
295
+ it "should return false for public instance methods on a subclass when the exclude_ancestors flag is false" do
296
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :public_instance_m, :instance_method_only, false).should be_false
297
+ end
298
+ it "should return false for protected instance methods on a subclass when the exclude_ancestors flag is false" do
299
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :protected_instance_m, :instance_method_only, false).should be_false
300
+ end
301
+ it "should return false for private instance methods on a subclass when the exclude_ancestors flag is false" do
302
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample2, :private_instance_m, :instance_method_only, false).should be_false
303
+ end
304
+
305
+ it "should return false for an unknown method" do
306
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :nonexistent_method).should be_false
307
+ end
308
+ it "should return false for an unknown method when only class methods are specified" do
309
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :nonexistent_method, :class_method_only).should be_false
310
+ end
311
+ it "should return false for an unknown method when only instance methods are specified" do
312
+ Aquarium::Utils::MethodUtils.has_method(MethodUtilsSpecProtectionExample.new, :nonexistent_method, :instance_method_only).should be_false
313
+ end
314
+ end
315
+
316
+ module DefinerModule1
317
+ def m1; end
318
+ end
319
+ module DefinerModule2
320
+ def m2; end
321
+ end
322
+ class DefinerClass1
323
+ include DefinerModule1
324
+ def c1; end
325
+ end
326
+ class DefinerClass2 < DefinerClass1
327
+ include DefinerModule2
328
+ def c2; end
329
+ end
330
+ class DefinerClass2b < DefinerClass1
331
+ include DefinerModule2
332
+ end
333
+
334
+ describe Aquarium::Utils::MethodUtils, ".definer" do
335
+ it "should return the type that defines the method, when given a type" do
336
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b, :c1).should == DefinerClass1
337
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b, :m1).should == DefinerModule1
338
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b, :m2).should == DefinerModule2
339
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2, :c2).should == DefinerClass2
340
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2, :c1).should == DefinerClass1
341
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2, :m1).should == DefinerModule1
342
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2, :m2).should == DefinerModule2
343
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1, :c1).should == DefinerClass1
344
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1, :m1).should == DefinerModule1
345
+ Aquarium::Utils::MethodUtils.definer(DefinerModule2, :m2).should == DefinerModule2
346
+ Aquarium::Utils::MethodUtils.definer(DefinerModule1, :m1).should == DefinerModule1
347
+ end
348
+
349
+ it "should return the type that defines the method, when given an object" do
350
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b.new, :c1).should == DefinerClass1
351
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b.new, :m1).should == DefinerModule1
352
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b.new, :m2).should == DefinerModule2
353
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2.new, :c2).should == DefinerClass2
354
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2.new, :c1).should == DefinerClass1
355
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2.new, :m1).should == DefinerModule1
356
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2.new, :m2).should == DefinerModule2
357
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1.new, :c1).should == DefinerClass1
358
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1.new, :m1).should == DefinerModule1
359
+ end
360
+
361
+ it "should return the eigenclass/singleton of an object when the method is defined on the object" do
362
+ dc = DefinerClass2.new
363
+ eigen = (class << dc; self; end)
364
+ def dc.dc1; end
365
+ Aquarium::Utils::MethodUtils.definer(dc, :dc1).should == eigen
366
+ end
367
+
368
+ it "should return the class of an object when the method is defined on the type or ancestor type, even if the eigenclass has been used to define an instance-only type" do
369
+ dc = DefinerClass2.new
370
+ eigen = (class << dc; self; end)
371
+ def dc.dc2; end
372
+ Aquarium::Utils::MethodUtils.definer(dc, :c2).should == DefinerClass2
373
+ Aquarium::Utils::MethodUtils.definer(dc, :m1).should == DefinerModule1
374
+ Aquarium::Utils::MethodUtils.definer(dc, :m2).should == DefinerModule2
375
+ end
376
+
377
+ it "should return nil if the specified method is defined by a subtype of the specified type" do
378
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1, :c2).should be_nil
379
+ Aquarium::Utils::MethodUtils.definer(DefinerModule1, :c2).should be_nil
380
+ Aquarium::Utils::MethodUtils.definer(DefinerModule2, :c2).should be_nil
381
+ end
382
+
383
+ it "should return nil if the specified method is defined by a subtype of the specified object's type" do
384
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1.new, :c2).should be_nil
385
+ Aquarium::Utils::MethodUtils.definer(DefinerClass2b.new, :c2).should be_nil
386
+ end
387
+
388
+ it "should return nil if nil is specified for the type or object" do
389
+ Aquarium::Utils::MethodUtils.definer(nil, :ignored).should be_nil
390
+ end
391
+
392
+ it "should return nil if nil is specified for the method" do
393
+ Aquarium::Utils::MethodUtils.definer(DefinerModule1, nil).should be_nil
394
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1, nil).should be_nil
395
+ Aquarium::Utils::MethodUtils.definer(DefinerClass1.new, nil).should be_nil
172
396
  end
173
397
  end