C0 code coverage information
Generated on Sun Oct 26 11:18:14 -0500 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'aquarium/spec_example_types'
3 require 'aquarium/finders/method_finder'
4
5 # :stopdoc:
6 class Base
7 def mbase1
8 end
9 def mbase2
10 end
11 end
12
13 module M
14 def mmodule1
15 end
16 def mmodule2
17 end
18 def self.cmmodule1
19 end
20 end
21
22 module M2
23 include M
24 def mmodule3
25 end
26 def mmodule4
27 end
28 def self.cmmodule3
29 end
30 end
31
32 class Derived < Base
33 include M
34 def mbase1
35 end
36 def mderived1
37 end
38 def mmodule1
39 end
40 def mmodule2b
41 end
42 end
43
44 class Derived2 < Base
45 include M2
46 def mbase1
47 end
48 def mderived1
49 end
50 def mmodule1
51 end
52 def mmodule2b
53 end
54 def mmodule3
55 end
56 def mmodule4b
57 end
58 end
59
60 # :startdoc:
61
62 def before_method_finder_spec
63 @test_classes = [
64 ClassWithPublicInstanceMethod,
65 ClassWithProtectedInstanceMethod,
66 ClassWithPrivateInstanceMethod,
67 ClassWithPublicClassMethod,
68 ClassWithPrivateClassMethod]
69 @pub = ClassWithPublicInstanceMethod.new
70 @pro = ClassWithProtectedInstanceMethod.new
71 @pri = ClassWithPrivateInstanceMethod.new
72 @cpub = ClassWithPublicClassMethod.new
73 @cpri = ClassWithPrivateClassMethod.new
74 @test_objects = [@pub, @pro, @pri, @cpub, @cpri]
75
76 @other_methods_expected = []
77 @empty_set = Set.new
78 end
79
80 describe Aquarium::Finders::MethodFinder, "#find (synonymous input parameters)" do
81 before(:each) do
82 @logger_stream = StringIO.new
83 before_method_finder_spec
84 end
85
86 Aquarium::Finders::MethodFinder::CANONICAL_OPTIONS["types"].each do |key|
87 it "should accept :#{key} as a synonym for :types." do
88 expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
89 actual = Aquarium::Finders::MethodFinder.new.find key.intern => Derived, :methods => [/^mbase/, /^mmodule/]
90 actual.should == expected
91 end
92 end
93
94 Aquarium::Finders::MethodFinder::CANONICAL_OPTIONS["objects"].each do |key|
95 it "should accept :#{key} as a synonym for :objects." do
96 child = Derived.new
97 expected = Aquarium::Finders::MethodFinder.new.find :objects => child, :methods => [/^mbase/, /^mmodule/]
98 actual = Aquarium::Finders::MethodFinder.new.find key.intern => child, :methods => [/^mbase/, /^mmodule/]
99 actual.should == expected
100 end
101 end
102
103 Aquarium::Finders::MethodFinder::CANONICAL_OPTIONS["methods"].each do |key|
104 it "should accept :#{key} as a synonym for :methods." do
105 expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
106 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, key.intern => [/^mbase/, /^mmodule/]
107 actual.should == expected
108 end
109 end
110
111 Aquarium::Finders::MethodFinder::CANONICAL_OPTIONS["method_options"].each do |key|
112 it "should accept :#{key} as a synonym for :method_options." do
113 expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mder/, /^mmod/], :method_options => [:exclude_ancestor_methods], :logger_stream => @logger_stream
114 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mder/, /^mmod/], key.intern => [:exclude_ancestor_methods], :logger_stream => @logger_stream
115 actual.should == expected
116 end
117 end
118
119 it "should warn that :options as a synonym for :method_options is deprecated." do
120 expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mder/, /^mmod/], :options => [:exclude_ancestor_methods], :logger_stream => @logger_stream
121 @logger_stream.to_s.grep(/WARN.*deprecated/).should_not be_nil
122 end
123
124 end
125
126 describe Aquarium::Finders::MethodFinder, "#find (invalid input parameters)" do
127 before(:each) do
128 before_method_finder_spec
129 end
130
131 it "should raise if unrecognized option specified." do
132 lambda { Aquarium::Finders::MethodFinder.new.find :tpye => "x", :ojbect => "y", :mehtod => "foo"}.should raise_error(Aquarium::Utils::InvalidOptions)
133 end
134
135 it "should raise if options include :singleton and :class, :public, :protected, or :private." do
136 lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :method_options => [:singleton, :class] }.should raise_error(Aquarium::Utils::InvalidOptions)
137 lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :method_options => [:singleton, :public] }.should raise_error(Aquarium::Utils::InvalidOptions)
138 lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :method_options => [:singleton, :protected] }.should raise_error(Aquarium::Utils::InvalidOptions)
139 lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :method_options => [:singleton, :private] }.should raise_error(Aquarium::Utils::InvalidOptions)
140 end
141 end
142
143 describe Aquarium::Finders::MethodFinder, "#find (input parameters that yield empty results)" do
144 before(:each) do
145 before_method_finder_spec
146 end
147
148 it "should return empty FinderResult#matched and FinderResult#not_matched hashes by default." do
149 actual = Aquarium::Finders::MethodFinder.new.find
150 actual.matched.should == {}
151 actual.not_matched.should == {}
152 end
153
154 it "should return empty FinderResult#matched and FinderResult#not_matched hashes if no types are specified." do
155 actual = Aquarium::Finders::MethodFinder.new.find :types => [], :methods => /instance_test_method/
156 actual.matched.should == {}
157 actual.not_matched.should == {}
158 end
159
160 it "should return empty FinderResult#matched and FinderResult#not_matched hashes if no objects are specified." do
161 actual = Aquarium::Finders::MethodFinder.new.find :objects => [], :methods => /instance_test_method/
162 actual.matched.should == {}
163 actual.not_matched.should == {}
164 end
165
166 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified types if no methods are specified." do
167 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod
168 actual.matched.should == {}
169 actual.not_matched.should == {ClassWithPublicInstanceMethod => @empty_set}
170 end
171 end
172
173 describe Aquarium::Finders::MethodFinder, "#find (input parameters specify no methods)" do
174 before(:each) do
175 before_method_finder_spec
176 end
177
178 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified objects if no methods are specified." do
179 pub = ClassWithPublicInstanceMethod.new
180 actual = Aquarium::Finders::MethodFinder.new.find :objects => pub
181 actual.matched.should == {}
182 actual.not_matched.should == {pub => @empty_set}
183 end
184
185 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified types if an empty methods list is specified." do
186 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => []
187 actual.matched.should == {}
188 actual.not_matched.should == {ClassWithPublicInstanceMethod => @empty_set}
189 end
190
191 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified objects if an empty methods list is specified." do
192 pub = ClassWithPublicInstanceMethod.new
193 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => []
194 actual.matched.should == {}
195 actual.not_matched.should == {pub => @empty_set}
196 end
197
198 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified types if an empty method name is specified." do
199 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => ""
200 actual.matched.should == {}
201 actual.not_matched.should == {ClassWithPublicInstanceMethod => Set.new([""])}
202 end
203
204 it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified objects if an empty method name is specified." do
205 pub = ClassWithPublicInstanceMethod.new
206 actual = Aquarium::Finders::MethodFinder.new.find :objects => pub, :methods => ""
207 actual.matched.should == {}
208 actual.not_matched.should == {pub => Set.new([""])}
209 end
210 end
211
212 describe Aquarium::Finders::MethodFinder, "#find (input parameters specify method regular expressions that match nothing)" do
213 before(:each) do
214 before_method_finder_spec
215 end
216
217 it "should find no methods when searching with one type and with a regexp matching no methods." do
218 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /no_matching_method/
219 actual.matched.should == {}
220 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/no_matching_method/])
221 end
222
223 it "should find no methods when searching with one object and with a regexp matching no methods." do
224 pub = ClassWithPublicInstanceMethod.new
225 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /no_matching_method/
226 actual.matched.should == {}
227 actual.not_matched[pub].should == Set.new([/no_matching_method/])
228 end
229 end
230
231 describe Aquarium::Finders::MethodFinder, "#find (input parameters specify method names that match nothing)" do
232 before(:each) do
233 before_method_finder_spec
234 end
235
236 it "should find no methods when searching with a type and with a literal name matching no methods." do
237 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => "no_matching_method"
238 actual.matched.should == {}
239 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new(["no_matching_method"])
240 end
241
242 it "should find no methods when searching with one object and with a literal name matching no methods." do
243 pub = ClassWithPublicInstanceMethod.new
244 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => "no_matching_method"
245 actual.matched.should == {}
246 actual.not_matched[pub].should == Set.new(["no_matching_method"])
247 end
248 end
249
250 describe Aquarium::Finders::MethodFinder, "#find (behavior for derived classes)" do
251 before(:each) do
252 before_method_finder_spec
253 end
254
255 it "should find base and derived methods in the specified class, by default." do
256 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
257 actual.matched.size.should == 1
258 actual.matched[Derived].should == Set.new([:mbase1, :mbase2, :mmodule1, :mmodule2, :mmodule2b])
259 end
260
261 it "should find base and derived methods in the specified object, by default." do
262 child = Derived.new
263 actual = Aquarium::Finders::MethodFinder.new.find :object => child, :methods => [/^mbase/, /^mderived/, /^mmodule/]
264 actual.matched.size.should == 1
265 actual.matched[child].should == Set.new([:mbase1, :mbase2, :mderived1, :mmodule1, :mmodule2, :mmodule2b])
266 end
267
268 it "should only find Derived methods for a type when ancestor methods are excluded, which also excludes method overrides." do
269 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mder/, /^mmod/], :method_options => [:exclude_ancestor_methods]
270 actual.matched.size.should == 1
271 actual.matched[Derived].should == Set.new([:mderived1, :mmodule2b])
272 end
273
274 it "should only find Derived methods for an object when ancestor methods are excluded, which also excludes method overrides." do
275 child = Derived.new
276 actual = Aquarium::Finders::MethodFinder.new.find :object => child, :methods => [/^mder/, /^mmodule/], :method_options => [:exclude_ancestor_methods]
277 actual.matched.size.should == 1
278 actual.matched[child].should == Set.new([:mderived1, :mmodule2b])
279 end
280 end
281
282 describe Aquarium::Finders::MethodFinder, "#find (behavior for included modules)" do
283 before(:each) do
284 before_method_finder_spec
285 end
286
287 it "should find included and defined methods in the specified modules, by default." do
288 actual = Aquarium::Finders::MethodFinder.new.find :type => [M, M2], :methods => /^mmodule/
289 actual.matched.size.should == 2
290 actual.matched[M].should == Set.new([:mmodule1, :mmodule2])
291 actual.matched[M2].should == Set.new([:mmodule1, :mmodule2, :mmodule3, :mmodule4])
292 end
293
294 it "should find included and overridden methods in classes that include the specified modules, by default." do
295 actual = Aquarium::Finders::MethodFinder.new.find :types => [Derived, Derived2], :methods => /^mmodule/
296 actual.matched.size.should == 2
297 actual.matched[Derived].should == Set.new([:mmodule1, :mmodule2, :mmodule2b])
298 actual.matched[Derived2].should == Set.new([:mmodule1, :mmodule2, :mmodule2b, :mmodule3, :mmodule4, :mmodule4b])
299 end
300
301 it "should find included and overridden methods in instances of classes that include the specified modules, by default." do
302 child = Derived.new
303 child2 = Derived2.new
304 actual = Aquarium::Finders::MethodFinder.new.find :objects => [child, child2], :methods => /^mmodule/
305 actual.matched.size.should == 2
306 actual.matched[child].should == Set.new([:mmodule1, :mmodule2, :mmodule2b])
307 actual.matched[child2].should == Set.new([:mmodule1, :mmodule2, :mmodule2b, :mmodule3, :mmodule4, :mmodule4b])
308 end
309
310 it "should only find defined methods for a module when ancestor methods are excluded, which also excludes method overrides." do
311 actual = Aquarium::Finders::MethodFinder.new.find :type => [M, M2], :methods => /^mmod/, :method_options => [:exclude_ancestor_methods]
312 actual.matched.size.should == 2
313 actual.matched[M].should == Set.new([:mmodule1, :mmodule2])
314 actual.matched[M2].should == Set.new([:mmodule3, :mmodule4])
315 end
316
317 it "should not find any methods from included modules in classes when ancestor methods are excluded, which also excludes method overrides." do
318 child = Derived.new
319 child2 = Derived2.new
320 actual = Aquarium::Finders::MethodFinder.new.find :objects => [child, child2], :methods => /^mmodule/, :method_options => [:exclude_ancestor_methods]
321 actual.matched.size.should == 2
322 actual.matched[child].should == Set.new([:mmodule2b])
323 actual.matched[child2].should == Set.new([:mmodule2b, :mmodule4b])
324 end
325 end
326
327 describe Aquarium::Finders::MethodFinder, "#find (searching for class methods)" do
328 before(:each) do
329 before_method_finder_spec
330 @expected_ClassWithPUblicClassMethod = Set.new(ClassWithPublicClassMethod.public_methods.reject{|m| m =~ /^__/}.sort.map{|m| m.intern})
331 @expected_ClassWithPrivateClassMethod = Set.new(ClassWithPrivateClassMethod.public_methods.reject{|m| m =~ /^__/}.sort.map{|m| m.intern})
332 end
333
334 it "should find all class methods specified by regular expression for types when :class is used." do
335 # NOTE: The list of methods defined by Kernel is different for MRI and JRuby!
336 expected = {}
337 expected[Kernel] = [:respond_to?]
338 expected[Kernel] += [:chomp!, :chop!] unless Object.const_defined?('JRUBY_VERSION')
339 [Object, Module, Class].each do |clazz|
340 expected[clazz] = [:respond_to?]
341 end
342 class_array = [Kernel, Module, Object, Class]
343 actual = Aquarium::Finders::MethodFinder.new.find :types => class_array, :methods => [/^resp.*\?$/, /^ch.*\!$/], :method_options => :class
344 class_array.each do |c|
345 actual.matched[c].should == Set.new(expected[c])
346 end
347 end
348
349 it "should ignore any methods that start with double underscores '__' by default when searching with the :all method specification and the :class option." do
350 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all, :method_options => :class
351 actual.matched.size.should == 2
352 actual.not_matched.size.should == 0
353 actual.matched[ClassWithPublicClassMethod].should == @expected_ClassWithPUblicClassMethod
354 actual.matched[ClassWithPrivateClassMethod].should == @expected_ClassWithPrivateClassMethod
355 end
356
357 it "should find any methods that start with double underscores '__' with the :include_system_methods option." do
358 class WithUnderScores
359 def self.__foo__; end
360 end
361 actual = Aquarium::Finders::MethodFinder.new.find :types => [WithUnderScores], :methods => :all, :method_options => [:class, :include_system_methods]
362 actual.matched[WithUnderScores].include?(:__foo__).should be_true
363 end
364
365 it "should find all public class methods in types when searching with the :all method specification and the :class option." do
366 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all, :method_options => :class
367 actual.matched.size.should == 2
368 actual.not_matched.size.should == 0
369 actual.matched[ClassWithPublicClassMethod].should == @expected_ClassWithPUblicClassMethod
370 actual.matched[ClassWithPrivateClassMethod].should == @expected_ClassWithPrivateClassMethod
371 end
372
373 it "should accept :all_methods as a synonym for :all." do
374 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all_methods, :method_options => :class
375 actual.matched.size.should == 2
376 actual.not_matched.size.should == 0
377 actual.matched[ClassWithPublicClassMethod].should == @expected_ClassWithPUblicClassMethod
378 actual.matched[ClassWithPrivateClassMethod].should == @expected_ClassWithPrivateClassMethod
379 end
380
381 it "should find all public class methods in types, but not ancestors, when searching with the :all method specification and the :class and :exclude_ancestor_methods options." do
382 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all, :method_options => [:class, :exclude_ancestor_methods]
383 actual.matched.size.should == 1
384 actual.not_matched.size.should == 1
385 actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
386 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([:all])
387 end
388 end
389
390 describe Aquarium::Finders::MethodFinder, "#find (searching for class methods defined in modules)" do
391 before(:each) do
392 before_method_finder_spec
393 end
394
395 def do_class_methods_for_modules method_spec, options_spec
396 actual = Aquarium::Finders::MethodFinder.new.find :type => [M, M2], :methods => method_spec, :method_options => options_spec
397 actual.matched.size.should == 2
398 actual.matched[M].should == Set.new([:cmmodule1])
399 actual.matched[M2].should == Set.new([:cmmodule3])
400 end
401
402 it "should find all class methods specified by regular expression for modules when :class is used." do
403 do_class_methods_for_modules /^cmmodule/, [:class]
404 end
405
406 it "should find all class methods specified by name for modules when :class is used." do
407 do_class_methods_for_modules [:cmmodule1, :cmmodule3], [:class]
408 end
409
410 it "should not find class methods defined in included modules, because they do not become class methods in the including module." do
411 do_class_methods_for_modules /^cmmodule/, [:class]
412 end
413
414 it "should not find class methods defined in included modules, if ancestor methods are excluded explicitly." do
415 do_class_methods_for_modules /^cmmodule/, [:class, :exclude_ancestor_methods]
416 end
417
418 it "should find all public class methods in types when searching with the :all method specification and the :class option." do
419 actual = Aquarium::Finders::MethodFinder.new.find :type => [M, M2], :methods => :all, :method_options => [:class]
420 actual.matched.size.should == 2
421 actual.matched[M].should == Set.new(M.public_methods.reject{|m| m =~ /^__/}.sort.map{|m| m.intern})
422 actual.matched[M2].should == Set.new(M2.public_methods.reject{|m| m =~ /^__/}.sort.map{|m| m.intern})
423 end
424
425 it "should not find any module-defined class methods in classes that include the modules." do
426 actual = Aquarium::Finders::MethodFinder.new.find :types => [Derived, Derived2], :methods => /^cmmodule/, :method_options => [:class]
427 actual.matched.size.should == 0
428 end
429
430 it "should not find any module-defined class methods in instances of classes that include the modules." do
431 child = Derived.new
432 child2 = Derived2.new
433 actual = Aquarium::Finders::MethodFinder.new.find :objects => [child, child2], :methods => /^cmmodule/, :method_options => [:class]
434 actual.matched.size.should == 0
435 end
436 end
437
438 describe Aquarium::Finders::MethodFinder, "#find (searching for instance methods)" do
439 before(:each) do
440 before_method_finder_spec
441 end
442
443 it "should ignore any methods that start with double underscores '__' by default when searching with the :all method specification and the :class option." do
444 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod], :methods => :all
445 actual.matched.size.should == 3
446 [ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod].each do |c|
447 actual.matched[c].each {|m| m.to_s.match('^__').should be_nil}
448 end
449 end
450
451 it "should find any methods that start with double underscores '__' with the :include_system_methods option." do
452 class WithUnderScores
453 def __foo__; end
454 end
455 actual = Aquarium::Finders::MethodFinder.new.find :types => [WithUnderScores], :methods => :all, :method_options => [:include_system_methods]
456 actual.matched[WithUnderScores].include?(:__foo__).should be_true
457 end
458
459 it "should find all public instance methods in classes when searching with the :all method specification." do
460 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod], :methods => :all
461 actual.matched.size.should == 3
462 [ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod].each do |c|
463 actual.matched[c].should == Set.new(c.public_instance_methods.reject{|m| m =~ /^__/}.sort.map {|m| m.intern})
464 end
465 end
466
467 it "should find all public instance methods in modules when searching with the :all method specification." do
468 actual = Aquarium::Finders::MethodFinder.new.find :types => [M, M2], :methods => :all
469 actual.matched.size.should == 2
470 actual.matched[M].should == Set.new([:mmodule1, :mmodule2])
471 actual.matched[M2].should == Set.new([:mmodule1, :mmodule2, :mmodule3, :mmodule4])
472 end
473
474 it "should find all public instance methods in objects when searching with the :all method specification." do
475 pub = ClassWithPublicInstanceMethod.new
476 pro = ClassWithProtectedInstanceMethod.new
477 pri = ClassWithPrivateInstanceMethod.new
478 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub, pro, pri], :methods => :all
479 actual.matched.size.should == 3
480 [pub, pro, pri].each do |c|
481 actual.matched[c].should == Set.new(c.public_methods.reject{|m| m =~ /^__/}.sort.map {|m| m.intern})
482 end
483 end
484
485 it "should find the module-defined public instance methods in when searching a class with the :all method specification." do
486 actual = Aquarium::Finders::MethodFinder.new.find :types => [Derived, Derived2], :methods => :all
487 actual.matched.size.should == 2
488 [:mmodule1, :mmodule2].each {|m| actual.matched[Derived].should include(m)}
489 [:mmodule1, :mmodule2, :mmodule3, :mmodule4].each {|m| actual.matched[Derived2].should include(m)}
490 end
491
492 it "should find the module-defined public instance methods in when searching an instance of a class with the :all method specification." do
493 child = Derived.new
494 child2 = Derived2.new
495 actual = Aquarium::Finders::MethodFinder.new.find :types => [child, child2], :methods => :all
496 actual.matched.size.should == 2
497 [:mmodule1, :mmodule2].each {|m| actual.matched[child].should include(m)}
498 [:mmodule1, :mmodule2, :mmodule3, :mmodule4].each {|m| actual.matched[child2].should include(m)}
499 end
500
501 it "should find only one instance method for a type when searching with a regexp matching one method." do
502 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test_method/
503 actual.matched.size.should == 1
504 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
505 actual2 = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test/
506 actual2.matched.size.should == 1
507 actual2.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
508 actual3 = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /test_method/
509 actual3.matched.size.should == 1
510 actual3.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
511 end
512
513 it "should find only one instance method for an object when searching with a regexp matching one method." do
514 pub = ClassWithPublicInstanceMethod.new
515 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /instance_test_method/
516 actual.matched.size.should == 1
517 actual.matched[pub].should == Set.new([:public_instance_test_method])
518 end
519
520 it "should find only one instance method for one class when searching with a one-class array and with a regexp matching one method." do
521 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => /instance_test_method/
522 actual.matched.size.should == 1
523 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
524 end
525
526 it "should find only one instance method for one object when searching with a one-object array and with a regexp matching one method." do
527 pub = ClassWithPublicInstanceMethod.new
528 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => /instance_test_method/
529 actual.matched.size.should == 1
530 actual.matched[pub].should == Set.new([:public_instance_test_method])
531 end
532
533 it "should find only one instance method for one class when searching with a one-class array and with a single-regexp array matching one method." do
534 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => [/instance_test_method/]
535 actual.matched.size.should == 1
536 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
537 end
538
539 it "should find only one instance method for one object when searching with a one-object array and with a single-regexp array matching one method." do
540 pub = ClassWithPublicInstanceMethod.new
541 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => [/instance_test_method/]
542 actual.matched.size.should == 1
543 actual.matched[pub].should == Set.new([:public_instance_test_method])
544 end
545
546 it "should find only one instance method for one class when searching with a one-class array and with the method's literal name." do
547 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => "public_instance_test_method"
548 actual.matched.size.should == 1
549 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
550 end
551
552 it "should find only one instance method for one object when searching with a one-object array and with the method's literal name." do
553 pub = ClassWithPublicInstanceMethod.new
554 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => "public_instance_test_method"
555 actual.matched.size.should == 1
556 actual.matched[pub].should == Set.new([:public_instance_test_method])
557 end
558
559 it "should find only one instance method for one class when searching with a one-class array and with the method's literal name in a single-element array." do
560 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => ["public_instance_test_method"]
561 actual.matched.size.should == 1
562 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
563 end
564
565 it "should find only one instance method for one object when searching with a one-object array and with the method's literal name in a single-element array." do
566 pub = ClassWithPublicInstanceMethod.new
567 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => ["public_instance_test_method"]
568 actual.matched.size.should == 1
569 actual.matched[pub].should == Set.new([:public_instance_test_method])
570 end
571
572 it "should find an instance method for each class when searching with a two-class array and with the methods' literal names." do
573 actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithPublicInstanceMethod2], :methods => ["public_instance_test_method", "public_instance_test_method2"]
574 actual.matched.size.should == 2
575 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
576 actual.matched[ClassWithPublicInstanceMethod2].should == Set.new([:public_instance_test_method2])
577 end
578
579 it "should find an instance method for each object when searching with a two-object array and with the methods' literal names." do
580 pub = ClassWithPublicInstanceMethod
581 pub2 = ClassWithPublicInstanceMethod2.new
582 actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub, pub2], :methods => ["public_instance_test_method", "public_instance_test_method2"]
583 actual.matched.size.should == 2
584 actual.matched[pub].should == Set.new([:public_instance_test_method])
585 actual.matched[pub2].should == Set.new([:public_instance_test_method2])
586 end
587 end
588
589 describe Aquarium::Finders::MethodFinder, "#find (format of results)" do
590 before(:each) do
591 before_method_finder_spec
592 end
593
594 it "should return found methods for a type as symbols." do
595 actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test_method/
596 actual.matched.size.should == 1
597 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
598 end
599
600 it "should return found methods for an object as symbols." do
601 pub = ClassWithPublicInstanceMethod.new
602 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /instance_test_method/
603 actual.matched.size.should == 1
604 actual.matched[pub].should == Set.new([:public_instance_test_method])
605 end
606 end
607
608 describe Aquarium::Finders::MethodFinder, "#find (using :methods => :all)" do
609 before(:each) do
610 before_method_finder_spec
611 end
612
613 it "should accept :all for the methods argument and find all methods for a type subject to the method options." do
614 actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPublicInstanceMethod, :method => :all, :method_options => :exclude_ancestor_methods
615 actual.matched.size.should == 1
616 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
617 end
618
619 it "should accept :all for the methods argument and find all methods for an object subject to the method options." do
620 pub = ClassWithPublicInstanceMethod.new
621 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :method => :all, :method_options => :exclude_ancestor_methods
622 actual.matched.size.should == 1
623 actual.matched[pub].should == Set.new([:public_instance_test_method])
624 end
625
626 it "should ignore other method arguments if :all is present." do
627 actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPublicInstanceMethod, :method => [:all, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :method_options => :exclude_ancestor_methods
628 actual.matched.size.should == 1
629 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
630 pub = ClassWithPublicInstanceMethod.new
631 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :method => [:all, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :method_options => :exclude_ancestor_methods
632 actual.matched.size.should == 1
633 actual.matched[pub].should == Set.new([:public_instance_test_method])
634 end
635
636 it "should ignore other method arguments if :all_methods is present." do
637 actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPublicInstanceMethod, :method => [:all_methods, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :method_options => :exclude_ancestor_methods
638 actual.matched.size.should == 1
639 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
640 pub = ClassWithPublicInstanceMethod.new
641 actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :method => [:all, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :method_options => :exclude_ancestor_methods
642 actual.matched.size.should == 1
643 actual.matched[pub].should == Set.new([:public_instance_test_method])
644 end
645
646 it "should report [:all] as the not_matched value when :all is the method argument and no methods match, e.g., for :exclude_ancestor_methods." do
647 actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPrivateInstanceMethod, :method => :all, :method_options => :exclude_ancestor_methods
648 actual.matched.size.should == 0
649 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([:all])
650 pri = ClassWithPrivateInstanceMethod.new
651 actual = Aquarium::Finders::MethodFinder.new.find :object => pri, :method => :all, :method_options => :exclude_ancestor_methods
652 actual.matched.size.should == 0
653 actual.not_matched[pri].should == Set.new([:all])
654 end
655 end
656
657 class ExcludeMethodTester
658 def method1; end
659 def method2; end
660 def method3; end
661 end
662
663 describe Aquarium::Finders::MethodFinder, "#find for types (using :exclude_methods)" do
664 it "should return an empty result for classes if :exclude_methods => :all specified." do
665 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_methods => :all, :method_options => :exclude_ancestor_methods
666 actual.matched.size.should == 0
667 actual.not_matched.size.should == 0
668 end
669 it "should return an empty result for modules if :exclude_methods => :all specified." do
670 actual = Aquarium::Finders::MethodFinder.new.find :types => M2, :methods => :all, :exclude_methods => :all, :method_options => :exclude_ancestor_methods
671 actual.matched.size.should == 0
672 actual.not_matched.size.should == 0
673 end
674 it "should return an empty result for classes including modules if :exclude_methods => :all specified." do
675 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived2, :methods => :all, :exclude_methods => :all, :method_options => :exclude_ancestor_methods
676 actual.matched.size.should == 0
677 actual.not_matched.size.should == 0
678 end
679
680 it "should remove excluded methods from the result for classes where a single excluded methods is specified by name." do
681 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_method => :method1, :method_options => :exclude_ancestor_methods
682 actual.matched.size.should == 1
683 actual.matched[ExcludeMethodTester].size.should == 2
684 actual.matched[ExcludeMethodTester].should == Set.new([:method2, :method3])
685 actual.not_matched.size.should == 0
686 end
687 it "should remove excluded methods from the result for modules where a single excluded methods is specified by name." do
688 actual = Aquarium::Finders::MethodFinder.new.find :types => M, :methods => :all, :exclude_method => :mmodule1
689 actual.matched.size.should == 1
690 actual.matched[M].size.should == 1
691 actual.matched[M].should == Set.new([:mmodule2])
692 actual.not_matched.size.should == 0
693 end
694 it "should remove excluded methods from the result for classes that include modules where a single excluded methods is specified by name." do
695 actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => :all, :exclude_method => :mmodule1
696 actual.matched.size.should == 1
697 actual.matched[Derived].should_not include(:mmodule1)
698 end
699
700 it "should remove excluded methods from the result where the excluded methods are specified by an array of names." do
701 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_methods => [:method1, :method2], :method_options => :exclude_ancestor_methods
702 actual.matched.size.should == 1
703 actual.matched[ExcludeMethodTester].size.should == 1
704 actual.matched[ExcludeMethodTester].should == Set.new([:method3])
705 actual.not_matched.size.should == 0
706 end
707
708 it "should remove excluded methods from the result where the excluded methods are specified by regular expression." do
709 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_methods => /meth.*1$/, :method_options => :exclude_ancestor_methods
710 actual.matched.size.should == 1
711 actual.matched[ExcludeMethodTester].size.should == 2
712 actual.matched[ExcludeMethodTester].should == Set.new([:method2, :method3])
713 actual.not_matched.size.should == 0
714 end
715
716 it "should support :exclude_method as a synonym." do
717 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_method => :method1, :method_options => :exclude_ancestor_methods
718 actual.matched.size.should == 1
719 actual.matched[ExcludeMethodTester].size.should == 2
720 actual.matched[ExcludeMethodTester].should == Set.new([:method2, :method3])
721 actual.not_matched.size.should == 0
722 end
723
724 it "should not add the excluded methods to the #not_matched results." do
725 actual = Aquarium::Finders::MethodFinder.new.find :types => ExcludeMethodTester, :methods => :all, :exclude_methods => /meth.*1$/, :method_options => :exclude_ancestor_methods
726 actual.not_matched.size.should == 0
727 end
728 end
729
730 describe Aquarium::Finders::MethodFinder, "#find for objects (using :exclude_methods)" do
731 it "should return an empty result for instances of classes if :exclude_methods => :all specified." do
732 actual = Aquarium::Finders::MethodFinder.new.find :object => ExcludeMethodTester.new, :methods => :all, :exclude_methods => :all, :method_options => :exclude_ancestor_methods
733 actual.matched.size.should == 0
734 actual.not_matched.size.should == 0
735 end
736 it "should return an empty result for for instances of classes that include modules if :exclude_methods => :all specified." do
737 actual = Aquarium::Finders::MethodFinder.new.find :object => Derived2.new, :methods => :all, :exclude_methods => :all, :method_options => :exclude_ancestor_methods
738 actual.matched.size.should == 0
739 actual.not_matched.size.should == 0
740 end
741
742 it "should remove excluded methods from the result where a single excluded methods is specified by name." do
743 emt = ExcludeMethodTester.new
744 actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_method => :method1, :method_options => :exclude_ancestor_methods
745 actual.matched.size.should == 1
746 actual.matched[emt].size.should == 2
747 actual.matched[emt].should == Set.new([:method2, :method3])
748 actual.not_matched.size.should == 0
749 end
750
751 it "should remove excluded methods from the result where the excluded methods are specified by an array of names." do
752 emt = ExcludeMethodTester.new
753 actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_methods => [:method1, :method2], :method_options => :exclude_ancestor_methods
754 actual.matched.size.should == 1
755 actual.matched[emt].size.should == 1
756 actual.matched[emt].should == Set.new([:method3])
757 actual.not_matched.size.should == 0
758 end
759
760 it "should remove excluded methods from the result where the excluded methods are specified by regular expression." do
761 emt = ExcludeMethodTester.new
762 actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_methods => /meth.*1$/, :method_options => :exclude_ancestor_methods
763 actual.matched.size.should == 1
764 actual.matched[emt].size.should == 2
765 actual.matched[emt].should == Set.new([:method2, :method3])
766 actual.not_matched.size.should == 0
767 end
768
769 it "should support :exclude_method as a synonym." do
770 emt = ExcludeMethodTester.new
771 actual = Aquarium::Finders::MethodFinder.new.find :object => emt, :methods => :all, :exclude_method => :method1, :method_options => :exclude_ancestor_methods
772 actual.matched.size.should == 1
773 actual.matched[emt].size.should == 2
774 actual.matched[emt].should == Set.new([:method2, :method3])
775 actual.not_matched.size.should == 0
776 end
777
778 it "should not add the excluded methods to the #not_matched results." do
779 actual = Aquarium::Finders::MethodFinder.new.find :object => ExcludeMethodTester.new, :methods => :all, :exclude_methods => /meth.*1$/, :method_options => :exclude_ancestor_methods
780 actual.not_matched.size.should == 0
781 end
782 end
783
784
785 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => :exclude_ancestor_methods)" do
786 before(:each) do
787 before_method_finder_spec
788 end
789
790 it "should suppress ancestor methods for classes when :exclude_ancestor_methods is specified." do
791 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:public, :instance, :exclude_ancestor_methods]
792 actual.matched.size.should == 1
793 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
794 actual.not_matched.size.should == 4
795 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
796 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
797 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
798 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
799 end
800 it "should suppress ancestor methods for objects when :exclude_ancestor_methods is specified." do
801 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:public, :instance, :exclude_ancestor_methods]
802 actual.matched.size.should == 1
803 actual.matched[@pub].should == Set.new([:public_instance_test_method])
804 actual.not_matched.size.should == 4
805 actual.not_matched[@pro].should == Set.new([/test_method/])
806 actual.not_matched[@pri].should == Set.new([/test_method/])
807 actual.not_matched[@cpub].should == Set.new([/test_method/])
808 actual.not_matched[@cpri].should == Set.new([/test_method/])
809 end
810
811 it "should suppress ancestor methods for modules when :exclude_ancestor_methods is specified." do
812 actual = Aquarium::Finders::MethodFinder.new.find :type => M2, :methods => /^mmodule/, :method_options => [:instance, :exclude_ancestor_methods]
813 actual.matched.size.should == 1
814 actual.matched[M2].should == Set.new([:mmodule3, :mmodule4])
815 actual.not_matched.size.should == 0
816 end
817 it "should suppress ancestor methods for classes including modules when :exclude_ancestor_methods is specified." do
818 actual = Aquarium::Finders::MethodFinder.new.find :types => [Derived, Derived2], :methods => /^mmodule/, :method_options => [:instance, :exclude_ancestor_methods]
819 actual.matched.size.should == 2
820 actual.matched[Derived].should == Set.new([:mmodule2b])
821 actual.matched[Derived2].should == Set.new([:mmodule2b, :mmodule4b])
822 actual.not_matched.size.should == 0
823 end
824 it "should suppress ancestor methods for instances of classes including modules when :exclude_ancestor_methods is specified." do
825 child = Derived.new
826 child2 = Derived2.new
827 actual = Aquarium::Finders::MethodFinder.new.find :types => [child, child2], :methods => /^mmodule/, :method_options => [:instance, :exclude_ancestor_methods]
828 actual.matched.size.should == 2
829 actual.matched[child].should == Set.new([:mmodule2b])
830 actual.matched[child2].should == Set.new([:mmodule2b, :mmodule4b])
831 actual.not_matched.size.should == 0
832 end
833 end
834
835 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:public, :instance])" do
836 before(:each) do
837 before_method_finder_spec
838 end
839
840 it "should find only public instance methods for types when :public, and :instance are specified." do
841 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:public, :instance, :exclude_ancestor_methods]
842 actual.matched.size.should == 1
843 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
844 actual.not_matched.size.should == 4
845 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
846 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
847 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
848 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
849 end
850
851 it "should find only public instance methods for objects when :public, and :instance are specified." do
852 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:public, :instance, :exclude_ancestor_methods]
853 actual.matched.size.should == 1
854 actual.matched[@pub].should == Set.new([:public_instance_test_method])
855 actual.not_matched.size.should == 4
856 actual.not_matched[@pro].should == Set.new([/test_method/])
857 actual.not_matched[@pri].should == Set.new([/test_method/])
858 actual.not_matched[@cpub].should == Set.new([/test_method/])
859 actual.not_matched[@cpri].should == Set.new([/test_method/])
860 end
861 end
862
863 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:protected, :instance])" do
864 before(:each) do
865 before_method_finder_spec
866 end
867
868 it "should find only protected instance methods when :protected, and :instance are specified." do
869 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:protected, :instance, :exclude_ancestor_methods]
870 actual.matched.size.should == 1
871 actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
872 actual.not_matched.size.should == 4
873 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
874 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
875 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
876 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
877 end
878
879 it "should find only protected instance methods for objects when :protected, and :instance are specified." do
880 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:protected, :instance, :exclude_ancestor_methods]
881 actual.matched.size.should == 1
882 actual.matched[@pro].should == Set.new([:protected_instance_test_method])
883 actual.not_matched.size.should == 4
884 actual.not_matched[@pub].should == Set.new([/test_method/])
885 actual.not_matched[@pri].should == Set.new([/test_method/])
886 actual.not_matched[@cpub].should == Set.new([/test_method/])
887 actual.not_matched[@cpri].should == Set.new([/test_method/])
888 end
889 end
890
891 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:private, :instance])" do
892 before(:each) do
893 before_method_finder_spec
894 end
895
896 it "should find only private instance methods when :private, and :instance are specified." do
897 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:private, :instance, :exclude_ancestor_methods]
898 actual.matched.size.should == 1
899 actual.matched[ClassWithPrivateInstanceMethod].should == Set.new([:private_instance_test_method])
900 actual.not_matched.size.should == 4
901 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
902 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
903 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
904 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
905 end
906
907 it "should find only private instance methods for objects when :private, and :instance are specified." do
908 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:private, :instance, :exclude_ancestor_methods]
909 actual.matched.size.should == 1
910 actual.matched[@pri].should == Set.new([:private_instance_test_method])
911 actual.not_matched.size.should == 4
912 actual.not_matched[@pub].should == Set.new([/test_method/])
913 actual.not_matched[@pro].should == Set.new([/test_method/])
914 actual.not_matched[@cpub].should == Set.new([/test_method/])
915 actual.not_matched[@cpri].should == Set.new([/test_method/])
916 end
917 end
918
919 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:public, :class])" do
920 before(:each) do
921 before_method_finder_spec
922 end
923
924 it "should find only public class methods for types when :public, and :class are specified." do
925 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:public, :class, :exclude_ancestor_methods]
926 actual.matched.size.should == 1
927 actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
928 actual.not_matched.size.should == 4
929 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
930 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
931 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
932 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
933 end
934
935 it "should find no public class methods for objects when :public, and :class are specified." do
936 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:public, :class, :exclude_ancestor_methods]
937 actual.matched.size.should == 0
938 actual.not_matched.size.should == 5
939 actual.not_matched[@pub].should == Set.new([/test_method/])
940 actual.not_matched[@pro].should == Set.new([/test_method/])
941 actual.not_matched[@pri].should == Set.new([/test_method/])
942 actual.not_matched[@cpub].should == Set.new([/test_method/])
943 actual.not_matched[@cpri].should == Set.new([/test_method/])
944 end
945 end
946
947 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:private, :class])" do
948 before(:each) do
949 before_method_finder_spec
950 end
951
952 it "should find only private class methods for types when :private, and :class are specified." do
953 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:private, :class, :exclude_ancestor_methods]
954 actual.matched.size.should == 1
955 actual.matched[ClassWithPrivateClassMethod].should == Set.new([:private_class_test_method])
956 actual.not_matched.size.should == 4
957 actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
958 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
959 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
960 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
961 end
962
963 it "should find no private class methods for objects when :private, and :class are specified." do
964 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:private, :class, :exclude_ancestor_methods]
965 actual.matched.size.should == 0
966 actual.not_matched.size.should == 5
967 actual.not_matched[@pub].should == Set.new([/test_method/])
968 actual.not_matched[@pro].should == Set.new([/test_method/])
969 actual.not_matched[@pri].should == Set.new([/test_method/])
970 actual.not_matched[@cpub].should == Set.new([/test_method/])
971 actual.not_matched[@cpri].should == Set.new([/test_method/])
972 end
973 end
974
975 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:public, :protected, :instance])" do
976 before(:each) do
977 before_method_finder_spec
978 end
979
980 it "should find public and protected instance methods for types when :public, :protected, and :instance are specified." do
981 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:public, :protected, :instance, :exclude_ancestor_methods]
982 actual.matched.size.should == 2
983 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
984 actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
985 actual.not_matched.size.should == 3
986 actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
987 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
988 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
989 end
990
991 it "should find public and protected instance methods for objects when :public, :protected, and :instance are specified." do
992 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:public, :protected, :instance, :exclude_ancestor_methods]
993 actual.matched.size.should == 2
994 actual.matched[@pub].should == Set.new([:public_instance_test_method])
995 actual.matched[@pro].should == Set.new([:protected_instance_test_method])
996 actual.not_matched.size.should == 3
997 actual.not_matched[@pri].should == Set.new([/test_method/])
998 actual.not_matched[@cpub].should == Set.new([/test_method/])
999 actual.not_matched[@cpri].should == Set.new([/test_method/])
1000 end
1001 end
1002
1003 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:public, :;private, :instance])" do
1004 before(:each) do
1005 before_method_finder_spec
1006 end
1007
1008 it "should find public and private instance methods when :public, :private, and :instance are specified." do
1009 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :method_options => [:public, :private, :instance, :exclude_ancestor_methods]
1010 actual.matched.size.should == 2
1011 actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
1012 actual.matched[ClassWithPrivateInstanceMethod].should == Set.new([:private_instance_test_method])
1013 actual.not_matched.size.should == 3
1014 actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
1015 actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
1016 actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
1017 end
1018
1019 it "should find public and private instance methods for objects when :public, :private, and :instance are specified." do
1020 actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :method_options => [:public, :private, :instance, :exclude_ancestor_methods]
1021 actual.matched.size.should == 2
1022 actual.matched[@pub].should == Set.new([:public_instance_test_method])
1023 actual.matched[@pri].should == Set.new([:private_instance_test_method])
1024 actual.not_matched.size.should == 3
1025 actual.not_matched[@pro].should == Set.new([/test_method/])
1026 actual.not_matched[@cpub].should == Set.new([/test_method/])
1027 actual.not_matched[@cpri].should == Set.new([/test_method/])
1028 end
1029 end
1030
1031 describe Aquarium::Finders::MethodFinder, "#find (using :method_options => [:protected, :private, :instance])" do
1032 before(:each) do
1033 before_method_finder_spec
1034 end
1035
1036 it "should find protected and private instance methods when :protected, :private, and :instance are specified." do
1037 actual = Aquarium::Finders::MethodFinder.new.find :types => @test_clas