aquarium 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/EXAMPLES.rd +4 -0
- data/MIT-LICENSE +20 -0
- data/README +250 -0
- data/RELEASE-PLAN +1 -0
- data/Rakefile +236 -0
- data/UPGRADE +3 -0
- data/examples/aspect_design_example.rb +36 -0
- data/examples/design_by_contract_example.rb +88 -0
- data/examples/method_missing_example.rb +44 -0
- data/examples/method_tracing_example.rb +64 -0
- data/lib/aquarium.rb +7 -0
- data/lib/aquarium/aspects.rb +6 -0
- data/lib/aquarium/aspects/advice.rb +189 -0
- data/lib/aquarium/aspects/aspect.rb +577 -0
- data/lib/aquarium/aspects/default_object_handler.rb +27 -0
- data/lib/aquarium/aspects/dsl.rb +1 -0
- data/lib/aquarium/aspects/dsl/aspect_dsl.rb +61 -0
- data/lib/aquarium/aspects/join_point.rb +158 -0
- data/lib/aquarium/aspects/pointcut.rb +254 -0
- data/lib/aquarium/aspects/pointcut_composition.rb +36 -0
- data/lib/aquarium/extensions.rb +5 -0
- data/lib/aquarium/extensions/hash.rb +85 -0
- data/lib/aquarium/extensions/regexp.rb +20 -0
- data/lib/aquarium/extensions/set.rb +49 -0
- data/lib/aquarium/extensions/string.rb +13 -0
- data/lib/aquarium/extensions/symbol.rb +22 -0
- data/lib/aquarium/extras.rb +4 -0
- data/lib/aquarium/extras/design_by_contract.rb +64 -0
- data/lib/aquarium/finders.rb +4 -0
- data/lib/aquarium/finders/finder_result.rb +121 -0
- data/lib/aquarium/finders/method_finder.rb +228 -0
- data/lib/aquarium/finders/object_finder.rb +74 -0
- data/lib/aquarium/finders/type_finder.rb +127 -0
- data/lib/aquarium/utils.rb +9 -0
- data/lib/aquarium/utils/array_utils.rb +29 -0
- data/lib/aquarium/utils/hash_utils.rb +28 -0
- data/lib/aquarium/utils/html_escaper.rb +17 -0
- data/lib/aquarium/utils/invalid_options.rb +9 -0
- data/lib/aquarium/utils/method_utils.rb +18 -0
- data/lib/aquarium/utils/nil_object.rb +13 -0
- data/lib/aquarium/utils/set_utils.rb +32 -0
- data/lib/aquarium/version.rb +30 -0
- data/rake_tasks/examples.rake +7 -0
- data/rake_tasks/examples_specdoc.rake +8 -0
- data/rake_tasks/examples_with_rcov.rake +8 -0
- data/rake_tasks/verify_rcov.rake +7 -0
- data/spec/aquarium/aspects/advice_chain_node_spec.rb +34 -0
- data/spec/aquarium/aspects/advice_spec.rb +103 -0
- data/spec/aquarium/aspects/aspect_invocation_spec.rb +111 -0
- data/spec/aquarium/aspects/aspect_spec.rb +978 -0
- data/spec/aquarium/aspects/aspect_with_nested_types_spec.rb +129 -0
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +423 -0
- data/spec/aquarium/aspects/concurrent_aspects_with_objects_and_types_spec.rb +103 -0
- data/spec/aquarium/aspects/concurrently_accessed.rb +21 -0
- data/spec/aquarium/aspects/dsl/aspect_dsl_spec.rb +514 -0
- data/spec/aquarium/aspects/join_point_spec.rb +302 -0
- data/spec/aquarium/aspects/pointcut_and_composition_spec.rb +131 -0
- data/spec/aquarium/aspects/pointcut_or_composition_spec.rb +111 -0
- data/spec/aquarium/aspects/pointcut_spec.rb +800 -0
- data/spec/aquarium/extensions/hash_spec.rb +187 -0
- data/spec/aquarium/extensions/regex_spec.rb +40 -0
- data/spec/aquarium/extensions/set_spec.rb +105 -0
- data/spec/aquarium/extensions/string_spec.rb +25 -0
- data/spec/aquarium/extensions/symbol_spec.rb +37 -0
- data/spec/aquarium/extras/design_by_contract_spec.rb +68 -0
- data/spec/aquarium/finders/finder_result_spec.rb +359 -0
- data/spec/aquarium/finders/method_finder_spec.rb +878 -0
- data/spec/aquarium/finders/method_sorting_spec.rb +16 -0
- data/spec/aquarium/finders/object_finder_spec.rb +230 -0
- data/spec/aquarium/finders/type_finder_spec.rb +210 -0
- data/spec/aquarium/spec_example_classes.rb +117 -0
- data/spec/aquarium/spec_helper.rb +3 -0
- data/spec/aquarium/utils/array_utils_spec.rb +47 -0
- data/spec/aquarium/utils/hash_utils_spec.rb +48 -0
- data/spec/aquarium/utils/html_escaper_spec.rb +18 -0
- data/spec/aquarium/utils/method_utils_spec.rb +50 -0
- data/spec/aquarium/utils/nil_object_spec.rb +19 -0
- data/spec/aquarium/utils/set_utils_spec.rb +60 -0
- metadata +132 -0
@@ -0,0 +1,359 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../spec_example_classes'
|
3
|
+
|
4
|
+
require 'aquarium/finders/finder_result'
|
5
|
+
require 'aquarium/extensions/set'
|
6
|
+
|
7
|
+
describe Aquarium::Finders::FinderResult, "#initialize" do
|
8
|
+
before do
|
9
|
+
@empty_set = Set.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create an empty finder result when no parameters are specified." do
|
13
|
+
result = Aquarium::Finders::FinderResult.new
|
14
|
+
result.matched.should == {}
|
15
|
+
result.not_matched.should == {}
|
16
|
+
result.empty?.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should accept a value for the :not_matched parameter and convert it into a hash with the input value as the key and an empty set as the corresponding value" do
|
20
|
+
result = Aquarium::Finders::FinderResult.new :not_matched => :b
|
21
|
+
result.not_matched.should == {:b => @empty_set}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept an array for the :not_matched parameter and convert it into a hash with the array values as the keys and empty sets as the corresponding values" do
|
25
|
+
result = Aquarium::Finders::FinderResult.new :not_matched => [:a, :b]
|
26
|
+
result.not_matched.should == {:a => @empty_set, :b => @empty_set}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should accept a hash for the :not_matched parameter and convert the values in the hashd into sets, if necessary." do
|
30
|
+
result = Aquarium::Finders::FinderResult.new :not_matched => {:a => 'a', :b => 'b'}
|
31
|
+
result.not_matched.should == {:a => Set.new(['a']), :b => Set.new(['b'])}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Aquarium::Finders::FinderResult, "#empty?" do
|
36
|
+
it "should be true if there are no matches." do
|
37
|
+
result = Aquarium::Finders::FinderResult.new
|
38
|
+
result.matched.should == {}
|
39
|
+
result.not_matched.should == {}
|
40
|
+
result.empty?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be true if there are no matches, even if there are not_matched values." do
|
44
|
+
result = Aquarium::Finders::FinderResult.new :not_matched => [:a, :b]
|
45
|
+
result.matched.should == {}
|
46
|
+
empty_set = Set.new
|
47
|
+
result.not_matched.should == {:a => empty_set, :b => empty_set}
|
48
|
+
result.empty?.should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Aquarium::Finders::FinderResult, "#not_matched" do
|
53
|
+
before do
|
54
|
+
@empty_set = Set.new
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return an empty hash for a default finder result." do
|
58
|
+
Aquarium::Finders::FinderResult.new.not_matched.should == {}
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return an empty hash if all the specified search items matched." do
|
62
|
+
result = Aquarium::Finders::FinderResult.new String =>["a", "b"], Hash => {:a => 'a'}
|
63
|
+
result.not_matched.should == {}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return a hash containing as keys the items specified with the :not_matched key in the input hash and empty sets as the corresponding values in the hash." do
|
67
|
+
result = Aquarium::Finders::FinderResult.new :not_matched =>[String, Hash]
|
68
|
+
result.not_matched.size == 2
|
69
|
+
result.not_matched[String].should == @empty_set
|
70
|
+
result.not_matched[Hash].should == @empty_set
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe Aquarium::Finders::FinderResult, "#not_matched_keys" do
|
75
|
+
it "should return an empty array by default." do
|
76
|
+
Aquarium::Finders::FinderResult.new.not_matched_keys.should == []
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return an empty array if all the specified search items matched." do
|
80
|
+
result = Aquarium::Finders::FinderResult.new String =>["a", "b"], Hash => {:a => 'a'}
|
81
|
+
result.not_matched_keys.should == []
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return an array containing the items specified with the :not_matched key in the input hash." do
|
85
|
+
result = Aquarium::Finders::FinderResult.new :not_matched =>[String, Hash]
|
86
|
+
result.not_matched_keys.size == 2
|
87
|
+
result.not_matched_keys.include?(String).should be(true)
|
88
|
+
result.not_matched_keys.include?(Hash).should be(true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe Aquarium::Finders::FinderResult, "#matched" do
|
93
|
+
it "should return an empty hash for a new result." do
|
94
|
+
Aquarium::Finders::FinderResult.new.matched.should == {}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return a hash of found search items where the found search items are the keys and arrays of corresponding objects are the corresponding values." do
|
98
|
+
result = Aquarium::Finders::FinderResult.new String => ["a", "b"], Hash => {:a => 'a'}
|
99
|
+
result.matched.size == 2
|
100
|
+
result.matched[String].should == Set.new(["a", "b"])
|
101
|
+
result.matched[Hash].should == Set.new([{:a => 'a'}])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Aquarium::Finders::FinderResult, "#matched_keys" do
|
106
|
+
it "should return an empty array by default." do
|
107
|
+
Aquarium::Finders::FinderResult.new.matched_keys.should == []
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return an empty array of found search items where the found search items are the keys and arrays of corresponding objects are the corresponding values." do
|
111
|
+
result = Aquarium::Finders::FinderResult.new String => ["a", "b"], Hash => {:a => 'a'}
|
112
|
+
result.matched_keys.size == 2
|
113
|
+
result.matched_keys.include?(String).should be(true)
|
114
|
+
result.matched_keys.include?(Hash).should be(true)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe Aquarium::Finders::FinderResult, "#<<" do
|
119
|
+
it "should return self." do
|
120
|
+
result1 = Aquarium::Finders::FinderResult.new
|
121
|
+
result = result1 << Aquarium::Finders::FinderResult.new
|
122
|
+
result.object_id.should be_equal(result1.object_id )
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should merge the value of the other FinderResult#not_matched into self's not_matched value." do
|
126
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:a => 'a'}
|
127
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b'}
|
128
|
+
result1 << result2
|
129
|
+
result1.not_matched.should == {:a => Set.new(['a']), :b => Set.new(['b'])}
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should merge the value of the other FinderResult#matched into self's matched value." do
|
133
|
+
result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2]
|
134
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
135
|
+
result1 << result2
|
136
|
+
result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should remove not_matched items when the same item is added to matched items from the right-hand side FinderResult." do
|
140
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b3, :c => :c1}, :a => [:a1, :a2]
|
141
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
142
|
+
result1 << result2
|
143
|
+
result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
144
|
+
result1.not_matched.should == {:b => Set.new([:b3]), :c => Set.new([:c1])}
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should remove not_matched items when the same item is added to matched items from the right-hand side FinderResult." do
|
148
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
|
149
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
150
|
+
result1 << result2
|
151
|
+
result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
152
|
+
result1.not_matched.should == {:b => Set.new([]), :c => Set.new([:c1])}
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "union of finder results", :shared => true do
|
157
|
+
it "should return a FinderResult equal to the second, non-empty FinderResult if the first FinderResult is empty." do
|
158
|
+
result1 = Aquarium::Finders::FinderResult.new
|
159
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
160
|
+
result = result1.or result2
|
161
|
+
result.should eql(result2)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return a FinderResult equal to the first, non-empty FinderResult if the second FinderResult is empty." do
|
165
|
+
result1 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
166
|
+
result2 = Aquarium::Finders::FinderResult.new
|
167
|
+
result = result1.or result2
|
168
|
+
result.should eql(result1)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return a FinderResult that is the union of self and the second FinderResult." do
|
172
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
173
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
174
|
+
result = result1.or result2
|
175
|
+
result.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
176
|
+
result.not_matched.should == {:b => Set.new(['b']), :c => Set.new(['c'])}
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should be unitary." do
|
180
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
181
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
182
|
+
result = result1.or result2
|
183
|
+
result.should eql(result1)
|
184
|
+
result.should eql(result2)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should be commutative." do
|
188
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
189
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
190
|
+
result12 = result1.or result2
|
191
|
+
result21 = result2.or result1
|
192
|
+
result12.should eql(result21)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should be associative." do
|
196
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
197
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
198
|
+
result3 = Aquarium::Finders::FinderResult.new :c => [:c1, :c2]
|
199
|
+
result123a = (result1.or result2).or result3
|
200
|
+
result123b = result1.or(result2.or(result3))
|
201
|
+
result123a.should eql(result123b)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe Aquarium::Finders::FinderResult, "#union" do
|
206
|
+
it_should_behave_like "union of finder results"
|
207
|
+
end
|
208
|
+
describe Aquarium::Finders::FinderResult, "#or" do
|
209
|
+
it_should_behave_like "union of finder results"
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "intersection of finder results", :shared => true do
|
213
|
+
it "should return an empty FinderResult if self is empty." do
|
214
|
+
result1 = Aquarium::Finders::FinderResult.new
|
215
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
216
|
+
result = result1.and result2
|
217
|
+
result.should eql(result1)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should return an empty FinderResult if the second FinderResult is empty." do
|
221
|
+
result1 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
222
|
+
result2 = Aquarium::Finders::FinderResult.new
|
223
|
+
result = result1.and result2
|
224
|
+
result.should eql(result2)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should return an empty FinderResult if there is no overlap between the two FinderResults." do
|
228
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b3, :c => :c1}, :a => [:a1, :a2]
|
229
|
+
result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
|
230
|
+
result = result1.and result2
|
231
|
+
result.matched.should be_empty
|
232
|
+
result.not_matched.should be_empty
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should return a FinderResult that is the intersection of self and the second FinderResult." do
|
236
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
|
237
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
|
238
|
+
result = result1.and result2
|
239
|
+
result.matched.should == {:a => Set.new([:a1])}
|
240
|
+
result.not_matched.should == {:b => Set.new([:b1])}
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should be unitary." do
|
244
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
245
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
|
246
|
+
result = result1.and result2
|
247
|
+
result.should eql(result1)
|
248
|
+
result.should eql(result2)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should be commutative." do
|
252
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
|
253
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
|
254
|
+
result12 = result1.and result2
|
255
|
+
result21 = result2.and result1
|
256
|
+
result12.should eql(result21)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should be associative." do
|
260
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
|
261
|
+
result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
|
262
|
+
result3 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1]}, :a => [:a1]
|
263
|
+
result123a = (result1.and result2).and result3
|
264
|
+
result123b = result1.and(result2.and(result3))
|
265
|
+
result123a.should eql(result123b)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe Aquarium::Finders::FinderResult, "#intersection" do
|
270
|
+
it_should_behave_like "intersection of finder results"
|
271
|
+
end
|
272
|
+
describe Aquarium::Finders::FinderResult, "#and" do
|
273
|
+
it_should_behave_like "intersection of finder results"
|
274
|
+
end
|
275
|
+
|
276
|
+
describe Aquarium::Finders::FinderResult, "#.append_matched" do
|
277
|
+
it "should not change self, if no arguments are specified." do
|
278
|
+
result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
|
279
|
+
result1.append_matched
|
280
|
+
result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should return the appended data when used with an empty finder result." do
|
284
|
+
result1 = Aquarium::Finders::FinderResult.new
|
285
|
+
result1.append_matched :a => [:a1, :a2], :b => [:b1, :b2]
|
286
|
+
result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should append the input hash to the corresponding keys and values." do
|
290
|
+
result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
|
291
|
+
result1.append_matched :a => [:a3, :a4], :b => [:b3], :c => [:c1, :c2]
|
292
|
+
result1.matched.should == {:a => Set.new([:a1, :a2, :a3, :a4]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1, :c2])}
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should accept single hash values as well as arrays of values." do
|
296
|
+
result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
|
297
|
+
result1.append_matched :a => :a3, :b => :b3, :c => :c1
|
298
|
+
result1.matched.should == {:a => Set.new([:a1, :a2, :a3]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1])}
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe Aquarium::Finders::FinderResult, "#.append_not_matched" do
|
303
|
+
it "should not change self, by default." do
|
304
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:a => [:a1, :a2], :b => [:b1, :b2]}
|
305
|
+
result1.append_not_matched
|
306
|
+
result1.not_matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should work with a default (empty) result." do
|
310
|
+
result1 = Aquarium::Finders::FinderResult.new
|
311
|
+
result1.append_not_matched :a => [:a1, :a2], :b => [:b1, :b2]
|
312
|
+
result1.not_matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should append the input hash to the corresponding keys and values." do
|
316
|
+
result1 = Aquarium::Finders::FinderResult.new :not_matched => {:a => [:a1, :a2], :b => [:b1, :b2]}
|
317
|
+
result1.append_not_matched :a => [:a3, :a4], :b => [:b3], :c => [:c1, :c2]
|
318
|
+
result1.not_matched.should == {:a => Set.new([:a1, :a2, :a3, :a4]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1, :c2])}
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "equality", :shared => true do
|
323
|
+
it "should return true for the same object." do
|
324
|
+
result = Aquarium::Finders::FinderResult.new
|
325
|
+
result.should be_eql(result)
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should return true for two default objects." do
|
329
|
+
result1 = Aquarium::Finders::FinderResult.new
|
330
|
+
result2 = Aquarium::Finders::FinderResult.new
|
331
|
+
result1.should eql(result2)
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should return false for two different objects that are equal and map to the same method." do
|
335
|
+
result1 = Aquarium::Finders::FinderResult.new ExampleParentClass.new => :a
|
336
|
+
result2 = Aquarium::Finders::FinderResult.new ExampleParentClass.new => :a
|
337
|
+
result1.should_not eql(result2)
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should return true if a key has a single value that equals the value in a 1-element array for the same key in the other FinderResult." do
|
341
|
+
result1 = Aquarium::Finders::FinderResult.new :a => 'a', :not_matched => {:b => 'b'}
|
342
|
+
result2 = Aquarium::Finders::FinderResult.new :a => ['a'], :not_matched => {:b => ['b']}
|
343
|
+
result1.should eql(result2)
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should return false for two objects that are different." do
|
347
|
+
result1 = Aquarium::Finders::FinderResult.new :a => 'a'
|
348
|
+
result2 = Aquarium::Finders::FinderResult.new :b => 'b'
|
349
|
+
result1.should_not eql(result2)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe Aquarium::Finders::FinderResult, "#eql?" do
|
354
|
+
it_should_behave_like "equality"
|
355
|
+
end
|
356
|
+
|
357
|
+
describe Aquarium::Finders::FinderResult, "#==" do
|
358
|
+
it_should_behave_like "equality"
|
359
|
+
end
|
@@ -0,0 +1,878 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../spec_example_classes'
|
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
|
+
end
|
19
|
+
|
20
|
+
class Derived < Base
|
21
|
+
include M
|
22
|
+
def mbase1
|
23
|
+
end
|
24
|
+
def mderived1
|
25
|
+
end
|
26
|
+
def mmodule1
|
27
|
+
end
|
28
|
+
def mmodule3
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# :startdoc:
|
33
|
+
|
34
|
+
def common_before
|
35
|
+
@test_classes = [
|
36
|
+
ClassWithPublicInstanceMethod,
|
37
|
+
ClassWithProtectedInstanceMethod,
|
38
|
+
ClassWithPrivateInstanceMethod,
|
39
|
+
ClassWithPublicClassMethod,
|
40
|
+
ClassWithPrivateClassMethod]
|
41
|
+
@pub = ClassWithPublicInstanceMethod.new
|
42
|
+
@pro = ClassWithProtectedInstanceMethod.new
|
43
|
+
@pri = ClassWithPrivateInstanceMethod.new
|
44
|
+
@cpub = ClassWithPublicClassMethod.new
|
45
|
+
@cpri = ClassWithPrivateClassMethod.new
|
46
|
+
@test_objects = [@pub, @pro, @pri, @cpub, @cpri]
|
47
|
+
|
48
|
+
@other_methods_expected = []
|
49
|
+
@empty_set = Set.new
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Aquarium::Finders::MethodFinder, "#find (synonymous input parameters)" do
|
53
|
+
before(:each) do
|
54
|
+
common_before
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should accept options :types and :type, which are synonymous." do
|
58
|
+
expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
|
59
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => Derived, :methods => [/^mbase/, /^mmodule/]
|
60
|
+
actual.should == expected
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should accept options :objects and :object, which are synonymous." do
|
64
|
+
child = Derived.new
|
65
|
+
expected = Aquarium::Finders::MethodFinder.new.find :objects => child, :methods => [/^mbase/, /^mmodule/]
|
66
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => child, :methods => [/^mbase/, /^mmodule/]
|
67
|
+
actual.should == expected
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should accept options :methods and :method, which are synonymous." do
|
71
|
+
expected = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
|
72
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :method => [/^mbase/, /^mmodule/]
|
73
|
+
actual.should == expected
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe Aquarium::Finders::MethodFinder, "#find (invalid input parameters)" do
|
78
|
+
before(:each) do
|
79
|
+
common_before
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise if unrecognized option specified." do
|
83
|
+
lambda { Aquarium::Finders::MethodFinder.new.find :tpye => "x", :ojbect => "y", :mehtod => "foo"}.should raise_error(Aquarium::Utils::InvalidOptions)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise if options include :singleton and :class, :public, :protected, or :private." do
|
87
|
+
lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :options => [:singleton, :class] }.should raise_error(Aquarium::Utils::InvalidOptions)
|
88
|
+
lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :options => [:singleton, :public] }.should raise_error(Aquarium::Utils::InvalidOptions)
|
89
|
+
lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :options => [:singleton, :protected] }.should raise_error(Aquarium::Utils::InvalidOptions)
|
90
|
+
lambda { Aquarium::Finders::MethodFinder.new.find :type => String, :method => "foo", :options => [:singleton, :private] }.should raise_error(Aquarium::Utils::InvalidOptions)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Aquarium::Finders::MethodFinder, "#find (input parameters that yield empty results)" do
|
95
|
+
before(:each) do
|
96
|
+
common_before
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return empty FinderResult#matched and FinderResult#not_matched hashes by default." do
|
100
|
+
actual = Aquarium::Finders::MethodFinder.new.find
|
101
|
+
actual.matched.should == {}
|
102
|
+
actual.not_matched.should == {}
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return empty FinderResult#matched and FinderResult#not_matched hashes if no types are specified." do
|
106
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [], :methods => /instance_test_method/
|
107
|
+
actual.matched.should == {}
|
108
|
+
actual.not_matched.should == {}
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return empty FinderResult#matched and FinderResult#not_matched hashes if no objects are specified." do
|
112
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [], :methods => /instance_test_method/
|
113
|
+
actual.matched.should == {}
|
114
|
+
actual.not_matched.should == {}
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified types if no methods are specified." do
|
118
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod
|
119
|
+
actual.matched.should == {}
|
120
|
+
actual.not_matched.should == {ClassWithPublicInstanceMethod => @empty_set}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe Aquarium::Finders::MethodFinder, "#find (input parameters specify no methods)" do
|
125
|
+
before(:each) do
|
126
|
+
common_before
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return an empty FinderResult#matched hash and a FinderResult#not_matched hash with the specified objects if no methods are specified." do
|
130
|
+
pub = ClassWithPublicInstanceMethod.new
|
131
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => pub
|
132
|
+
actual.matched.should == {}
|
133
|
+
actual.not_matched.should == {pub => @empty_set}
|
134
|
+
end
|
135
|
+
|
136
|
+
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
|
137
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => []
|
138
|
+
actual.matched.should == {}
|
139
|
+
actual.not_matched.should == {ClassWithPublicInstanceMethod => @empty_set}
|
140
|
+
end
|
141
|
+
|
142
|
+
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
|
143
|
+
pub = ClassWithPublicInstanceMethod.new
|
144
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => []
|
145
|
+
actual.matched.should == {}
|
146
|
+
actual.not_matched.should == {pub => @empty_set}
|
147
|
+
end
|
148
|
+
|
149
|
+
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
|
150
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => ""
|
151
|
+
actual.matched.should == {}
|
152
|
+
actual.not_matched.should == {ClassWithPublicInstanceMethod => Set.new([""])}
|
153
|
+
end
|
154
|
+
|
155
|
+
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
|
156
|
+
pub = ClassWithPublicInstanceMethod.new
|
157
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => pub, :methods => ""
|
158
|
+
actual.matched.should == {}
|
159
|
+
actual.not_matched.should == {pub => Set.new([""])}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe Aquarium::Finders::MethodFinder, "#find (input parameters specify method regular expressions that match nothing)" do
|
164
|
+
before(:each) do
|
165
|
+
common_before
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should find no methods when searching with one type and with a regexp matching no methods." do
|
169
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /no_matching_method/
|
170
|
+
actual.matched.should == {}
|
171
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/no_matching_method/])
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should find no methods when searching with one object and with a regexp matching no methods." do
|
175
|
+
pub = ClassWithPublicInstanceMethod.new
|
176
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /no_matching_method/
|
177
|
+
actual.matched.should == {}
|
178
|
+
actual.not_matched[pub].should == Set.new([/no_matching_method/])
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe Aquarium::Finders::MethodFinder, "#find (input parameters specify method names that match nothing)" do
|
183
|
+
before(:each) do
|
184
|
+
common_before
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should find no methods when searching with a type and with a literal name matching no methods." do
|
188
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => "no_matching_method"
|
189
|
+
actual.matched.should == {}
|
190
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new(["no_matching_method"])
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should find no methods when searching with one object and with a literal name matching no methods." do
|
194
|
+
pub = ClassWithPublicInstanceMethod.new
|
195
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => "no_matching_method"
|
196
|
+
actual.matched.should == {}
|
197
|
+
actual.not_matched[pub].should == Set.new(["no_matching_method"])
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe Aquarium::Finders::MethodFinder, "#find (behavior for derived classes)" do
|
202
|
+
before(:each) do
|
203
|
+
common_before
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should find Base and Derived methods in the specified class, by default." do
|
207
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mbase/, /^mmodule/]
|
208
|
+
actual.matched.size.should == 1
|
209
|
+
actual.matched[Derived].should == Set.new([:mbase1, :mbase2, :mmodule1, :mmodule2, :mmodule3])
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should find Base and Derived methods in the specified object, by default." do
|
213
|
+
child = Derived.new
|
214
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => child, :methods => [/^mbase/, /^mderived/, /^mmodule/]
|
215
|
+
actual.matched.size.should == 1
|
216
|
+
actual.matched[child].should == Set.new([:mbase1, :mbase2, :mderived1, :mmodule1, :mmodule2, :mmodule3])
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should find Derived methods only for a type when ancestor methods are suppressed, which also suppresses method overrides." do
|
220
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => Derived, :methods => [/^mder/, /^mmod/], :options => [:suppress_ancestor_methods]
|
221
|
+
actual.matched.size.should == 1
|
222
|
+
actual.matched[Derived].should == Set.new([:mderived1, :mmodule3])
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should find Derived methods only for an object when ancestor methods are suppressed, which also suppresses method overrides." do
|
226
|
+
child = Derived.new
|
227
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => child, :methods => [/^mder/, /^mmodule/], :options => [:suppress_ancestor_methods]
|
228
|
+
actual.matched.size.should == 1
|
229
|
+
actual.matched[child].should == Set.new([:mderived1, :mmodule3])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe Aquarium::Finders::MethodFinder, "#find (searching for class methods)" do
|
234
|
+
before(:each) do
|
235
|
+
common_before
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should find all class methods matching a regular expression for types when :class is used." do
|
239
|
+
# Have to add some rspec methods to the expected lists!
|
240
|
+
rspec_expected = %w[received_message?]
|
241
|
+
expected = {}
|
242
|
+
expected[Kernel] = (rspec_expected + %w[chomp! chop! class_variable_defined? const_defined? respond_to?]).sort.map {|m| m.intern}
|
243
|
+
[Object, Module, Class].each do |clazz|
|
244
|
+
expected[clazz] = (rspec_expected + %w[class_variable_defined? const_defined? respond_to?]).sort.map {|m| m.intern}
|
245
|
+
end
|
246
|
+
class_array = [Kernel, Module, Object, Class]
|
247
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => class_array, :methods => [/^[cr].*\?$/, /^[cr].*\!$/], :options => :class
|
248
|
+
class_array.each do |c|
|
249
|
+
actual.matched[c].should == Set.new(expected[c])
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should find all public class methods in types when searching with the :all method specification and the :class option." do
|
254
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all, :options => :class
|
255
|
+
actual.matched.size.should == 2
|
256
|
+
actual.not_matched.size.should == 0
|
257
|
+
actual.matched[ClassWithPublicClassMethod].should == Set.new(ClassWithPublicClassMethod.public_methods.sort.map{|m| m.intern})
|
258
|
+
actual.matched[ClassWithPrivateClassMethod].should == Set.new(ClassWithPrivateClassMethod.public_methods.sort.map{|m| m.intern})
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should find all public class methods in types, but not ancestors, when searching with the :all method specification and the :class and :suppress_ancestor_methods options." do
|
262
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicClassMethod, ClassWithPrivateClassMethod], :methods => :all, :options => [:class, :suppress_ancestor_methods]
|
263
|
+
actual.matched.size.should == 1
|
264
|
+
actual.not_matched.size.should == 1
|
265
|
+
actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
|
266
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([:all])
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe Aquarium::Finders::MethodFinder, "#find (searching for instance methods)" do
|
271
|
+
before(:each) do
|
272
|
+
common_before
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should find all public instance methods in types when searching with the :all method specification." do
|
276
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod], :methods => :all
|
277
|
+
actual.matched.size.should == 3
|
278
|
+
[ClassWithPublicInstanceMethod, ClassWithProtectedInstanceMethod, ClassWithPrivateInstanceMethod].each do |c|
|
279
|
+
actual.matched[c].should == Set.new(c.public_instance_methods.sort.map {|m| m.intern})
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should find all public instance methods in objects when searching with the :all method specification." do
|
284
|
+
pub = ClassWithPublicInstanceMethod.new
|
285
|
+
pro = ClassWithProtectedInstanceMethod.new
|
286
|
+
pri = ClassWithPrivateInstanceMethod.new
|
287
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub, pro, pri], :methods => :all
|
288
|
+
actual.matched.size.should == 3
|
289
|
+
[pub, pro, pri].each do |c|
|
290
|
+
actual.matched[c].should == Set.new(c.public_methods.sort.map {|m| m.intern})
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should find only one instance method for a type when searching with a regexp matching one method." do
|
295
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test_method/
|
296
|
+
actual.matched.size.should == 1
|
297
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should find only one instance method for an object when searching with a regexp matching one method." do
|
301
|
+
pub = ClassWithPublicInstanceMethod.new
|
302
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /instance_test_method/
|
303
|
+
actual.matched.size.should == 1
|
304
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
305
|
+
end
|
306
|
+
|
307
|
+
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
|
308
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => /instance_test_method/
|
309
|
+
actual.matched.size.should == 1
|
310
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
311
|
+
end
|
312
|
+
|
313
|
+
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
|
314
|
+
pub = ClassWithPublicInstanceMethod.new
|
315
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => /instance_test_method/
|
316
|
+
actual.matched.size.should == 1
|
317
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
318
|
+
end
|
319
|
+
|
320
|
+
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
|
321
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => [/instance_test_method/]
|
322
|
+
actual.matched.size.should == 1
|
323
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
324
|
+
end
|
325
|
+
|
326
|
+
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
|
327
|
+
pub = ClassWithPublicInstanceMethod.new
|
328
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => [/instance_test_method/]
|
329
|
+
actual.matched.size.should == 1
|
330
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
331
|
+
end
|
332
|
+
|
333
|
+
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
|
334
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => "public_instance_test_method"
|
335
|
+
actual.matched.size.should == 1
|
336
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
337
|
+
end
|
338
|
+
|
339
|
+
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
|
340
|
+
pub = ClassWithPublicInstanceMethod.new
|
341
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => "public_instance_test_method"
|
342
|
+
actual.matched.size.should == 1
|
343
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
344
|
+
end
|
345
|
+
|
346
|
+
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
|
347
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod], :methods => ["public_instance_test_method"]
|
348
|
+
actual.matched.size.should == 1
|
349
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
350
|
+
end
|
351
|
+
|
352
|
+
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
|
353
|
+
pub = ClassWithPublicInstanceMethod.new
|
354
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub], :methods => ["public_instance_test_method"]
|
355
|
+
actual.matched.size.should == 1
|
356
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should find an instance method for each class when searching with a two-class array and with the methods' literal names." do
|
360
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithPublicInstanceMethod2], :methods => ["public_instance_test_method", "public_instance_test_method2"]
|
361
|
+
actual.matched.size.should == 2
|
362
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
363
|
+
actual.matched[ClassWithPublicInstanceMethod2].should == Set.new([:public_instance_test_method2])
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should find an instance method for each object when searching with a two-object array and with the methods' literal names." do
|
367
|
+
pub = ClassWithPublicInstanceMethod
|
368
|
+
pub2 = ClassWithPublicInstanceMethod2.new
|
369
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [pub, pub2], :methods => ["public_instance_test_method", "public_instance_test_method2"]
|
370
|
+
actual.matched.size.should == 2
|
371
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
372
|
+
actual.matched[pub2].should == Set.new([:public_instance_test_method2])
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
describe Aquarium::Finders::MethodFinder, "#find (format of results)" do
|
377
|
+
before(:each) do
|
378
|
+
common_before
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should return found methods for a type as symbols." do
|
382
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPublicInstanceMethod, :methods => /instance_test_method/
|
383
|
+
actual.matched.size.should == 1
|
384
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should return found methods for an object as symbols." do
|
388
|
+
pub = ClassWithPublicInstanceMethod.new
|
389
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :methods => /instance_test_method/
|
390
|
+
actual.matched.size.should == 1
|
391
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :methods => :all)" do
|
396
|
+
before(:each) do
|
397
|
+
common_before
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should accept :all for the methods argument and find all methods for a type subject to the method options." do
|
401
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPublicInstanceMethod, :method => :all, :options => :suppress_ancestor_methods
|
402
|
+
actual.matched.size.should == 1
|
403
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should accept :all for the methods argument and find all methods for an object subject to the method options." do
|
407
|
+
pub = ClassWithPublicInstanceMethod.new
|
408
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :method => :all, :options => :suppress_ancestor_methods
|
409
|
+
actual.matched.size.should == 1
|
410
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should ignore other method arguments if :all is present." do
|
414
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPublicInstanceMethod, :method => [:all, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :options => :suppress_ancestor_methods
|
415
|
+
actual.matched.size.should == 1
|
416
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
417
|
+
pub = ClassWithPublicInstanceMethod.new
|
418
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pub, :method => [:all, :none, /.*foo.*/], :methods =>[/.*bar.*/, /^baz/], :options => :suppress_ancestor_methods
|
419
|
+
actual.matched.size.should == 1
|
420
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should report [:all] as the not_matched value when :all is the method argument and no methods match, e.g., for :suppress_ancestor_methods." do
|
424
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithPrivateInstanceMethod, :method => :all, :options => :suppress_ancestor_methods
|
425
|
+
actual.matched.size.should == 0
|
426
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([:all])
|
427
|
+
pri = ClassWithPrivateInstanceMethod.new
|
428
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => pri, :method => :all, :options => :suppress_ancestor_methods
|
429
|
+
actual.matched.size.should == 0
|
430
|
+
actual.not_matched[pri].should == Set.new([:all])
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => :suppress_ancestor_methods)" do
|
435
|
+
before(:each) do
|
436
|
+
common_before
|
437
|
+
end
|
438
|
+
|
439
|
+
it "should suppress ancestor methods for types when :suppress_ancestor_methods is specified." do
|
440
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :instance, :suppress_ancestor_methods]
|
441
|
+
actual.matched.size.should == 1
|
442
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
443
|
+
actual.not_matched.size.should == 4
|
444
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
445
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
446
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
447
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should suppress ancestor methods for objects when :suppress_ancestor_methods is specified." do
|
451
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :instance, :suppress_ancestor_methods]
|
452
|
+
actual.matched.size.should == 1
|
453
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
454
|
+
actual.not_matched.size.should == 4
|
455
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
456
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
457
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
458
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :instance])" do
|
463
|
+
before(:each) do
|
464
|
+
common_before
|
465
|
+
end
|
466
|
+
|
467
|
+
it "should find only public instance methods for types when :public, and :instance are specified." do
|
468
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :instance, :suppress_ancestor_methods]
|
469
|
+
actual.matched.size.should == 1
|
470
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
471
|
+
actual.not_matched.size.should == 4
|
472
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
473
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
474
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
475
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
476
|
+
end
|
477
|
+
|
478
|
+
it "should find only public instance methods for objects when :public, and :instance are specified." do
|
479
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :instance, :suppress_ancestor_methods]
|
480
|
+
actual.matched.size.should == 1
|
481
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
482
|
+
actual.not_matched.size.should == 4
|
483
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
484
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
485
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
486
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:protected, :instance])" do
|
491
|
+
before(:each) do
|
492
|
+
common_before
|
493
|
+
end
|
494
|
+
|
495
|
+
it "should find only protected instance methods when :protected, and :instance are specified." do
|
496
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:protected, :instance, :suppress_ancestor_methods]
|
497
|
+
actual.matched.size.should == 1
|
498
|
+
actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
|
499
|
+
actual.not_matched.size.should == 4
|
500
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
|
501
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
502
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
503
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should find only protected instance methods for objects when :protected, and :instance are specified." do
|
507
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:protected, :instance, :suppress_ancestor_methods]
|
508
|
+
actual.matched.size.should == 1
|
509
|
+
actual.matched[@pro].should == Set.new([:protected_instance_test_method])
|
510
|
+
actual.not_matched.size.should == 4
|
511
|
+
actual.not_matched[@pub].should == Set.new([/test_method/])
|
512
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
513
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
514
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:private, :instance])" do
|
519
|
+
before(:each) do
|
520
|
+
common_before
|
521
|
+
end
|
522
|
+
|
523
|
+
it "should find only private instance methods when :private, and :instance are specified." do
|
524
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:private, :instance, :suppress_ancestor_methods]
|
525
|
+
actual.matched.size.should == 1
|
526
|
+
actual.matched[ClassWithPrivateInstanceMethod].should == Set.new([:private_instance_test_method])
|
527
|
+
actual.not_matched.size.should == 4
|
528
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
|
529
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
530
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
531
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
532
|
+
end
|
533
|
+
|
534
|
+
it "should find only private instance methods for objects when :private, and :instance are specified." do
|
535
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:private, :instance, :suppress_ancestor_methods]
|
536
|
+
actual.matched.size.should == 1
|
537
|
+
actual.matched[@pri].should == Set.new([:private_instance_test_method])
|
538
|
+
actual.not_matched.size.should == 4
|
539
|
+
actual.not_matched[@pub].should == Set.new([/test_method/])
|
540
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
541
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
542
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :class])" do
|
547
|
+
before(:each) do
|
548
|
+
common_before
|
549
|
+
end
|
550
|
+
|
551
|
+
it "should find only public class methods for types when :public, and :class are specified." do
|
552
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :class, :suppress_ancestor_methods]
|
553
|
+
actual.matched.size.should == 1
|
554
|
+
actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
|
555
|
+
actual.not_matched.size.should == 4
|
556
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
|
557
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
558
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
559
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
560
|
+
end
|
561
|
+
|
562
|
+
it "should find no public class methods for objects when :public, and :class are specified." do
|
563
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :class, :suppress_ancestor_methods]
|
564
|
+
actual.matched.size.should == 0
|
565
|
+
actual.not_matched.size.should == 5
|
566
|
+
actual.not_matched[@pub].should == Set.new([/test_method/])
|
567
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
568
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
569
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
570
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:private, :class])" do
|
575
|
+
before(:each) do
|
576
|
+
common_before
|
577
|
+
end
|
578
|
+
|
579
|
+
it "should find only private class methods for types when :private, and :class are specified." do
|
580
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:private, :class, :suppress_ancestor_methods]
|
581
|
+
actual.matched.size.should == 1
|
582
|
+
actual.matched[ClassWithPrivateClassMethod].should == Set.new([:private_class_test_method])
|
583
|
+
actual.not_matched.size.should == 4
|
584
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
|
585
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
586
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
587
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
588
|
+
end
|
589
|
+
|
590
|
+
it "should find no private class methods for objects when :private, and :class are specified." do
|
591
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:private, :class, :suppress_ancestor_methods]
|
592
|
+
actual.matched.size.should == 0
|
593
|
+
actual.not_matched.size.should == 5
|
594
|
+
actual.not_matched[@pub].should == Set.new([/test_method/])
|
595
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
596
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
597
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
598
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :protected, :instance])" do
|
603
|
+
before(:each) do
|
604
|
+
common_before
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should find public and protected instance methods for types when :public, :protected, and :instance are specified." do
|
608
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :protected, :instance, :suppress_ancestor_methods]
|
609
|
+
actual.matched.size.should == 2
|
610
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
611
|
+
actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
|
612
|
+
actual.not_matched.size.should == 3
|
613
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
614
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
615
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
616
|
+
end
|
617
|
+
|
618
|
+
it "should find public and protected instance methods for objects when :public, :protected, and :instance are specified." do
|
619
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :protected, :instance, :suppress_ancestor_methods]
|
620
|
+
actual.matched.size.should == 2
|
621
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
622
|
+
actual.matched[@pro].should == Set.new([:protected_instance_test_method])
|
623
|
+
actual.not_matched.size.should == 3
|
624
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
625
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
626
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :;private, :instance])" do
|
631
|
+
before(:each) do
|
632
|
+
common_before
|
633
|
+
end
|
634
|
+
|
635
|
+
it "should find public and private instance methods when :public, :private, and :instance are specified." do
|
636
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :private, :instance, :suppress_ancestor_methods]
|
637
|
+
actual.matched.size.should == 2
|
638
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
639
|
+
actual.matched[ClassWithPrivateInstanceMethod].should == Set.new([:private_instance_test_method])
|
640
|
+
actual.not_matched.size.should == 3
|
641
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
642
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
643
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
644
|
+
end
|
645
|
+
|
646
|
+
it "should find public and private instance methods for objects when :public, :private, and :instance are specified." do
|
647
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :private, :instance, :suppress_ancestor_methods]
|
648
|
+
actual.matched.size.should == 2
|
649
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
650
|
+
actual.matched[@pri].should == Set.new([:private_instance_test_method])
|
651
|
+
actual.not_matched.size.should == 3
|
652
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
653
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
654
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
655
|
+
end
|
656
|
+
end
|
657
|
+
|
658
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:protected, :private, :instance])" do
|
659
|
+
before(:each) do
|
660
|
+
common_before
|
661
|
+
end
|
662
|
+
|
663
|
+
it "should find protected and private instance methods when :protected, :private, and :instance are specified." do
|
664
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:protected, :private, :instance, :suppress_ancestor_methods]
|
665
|
+
actual.matched.size.should == 2
|
666
|
+
actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
|
667
|
+
actual.matched[ClassWithPrivateInstanceMethod].should == Set.new([:private_instance_test_method])
|
668
|
+
actual.not_matched.size.should == 3
|
669
|
+
actual.not_matched[ClassWithPublicInstanceMethod].should == Set.new([/test_method/])
|
670
|
+
actual.not_matched[ClassWithPublicClassMethod].should == Set.new([/test_method/])
|
671
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
672
|
+
end
|
673
|
+
|
674
|
+
it "should find protected and private instance methods for objects when :protected, :private, and :instance are specified." do
|
675
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:protected, :private, :instance, :suppress_ancestor_methods]
|
676
|
+
actual.matched.size.should == 2
|
677
|
+
actual.matched[@pro].should == Set.new([:protected_instance_test_method])
|
678
|
+
actual.matched[@pri].should == Set.new([:private_instance_test_method])
|
679
|
+
actual.not_matched.size.should == 3
|
680
|
+
actual.not_matched[@pub].should == Set.new([/test_method/])
|
681
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
682
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :class, :instance])" do
|
687
|
+
before(:each) do
|
688
|
+
common_before
|
689
|
+
end
|
690
|
+
|
691
|
+
it "should find public class and instance methods for types when :public, :class, and :instance are specified." do
|
692
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :class, :instance, :suppress_ancestor_methods]
|
693
|
+
actual.matched.size.should == 2
|
694
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
695
|
+
actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
|
696
|
+
actual.not_matched.size.should == 3
|
697
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
698
|
+
actual.not_matched[ClassWithProtectedInstanceMethod].should == Set.new([/test_method/])
|
699
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
700
|
+
end
|
701
|
+
|
702
|
+
it "should find only public instance methods for objects even when :class is specified along with :public and :instance." do
|
703
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :class, :instance, :suppress_ancestor_methods]
|
704
|
+
actual.matched.size.should == 1
|
705
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
706
|
+
actual.not_matched.size.should == 4
|
707
|
+
actual.not_matched[@pro].should == Set.new([/test_method/])
|
708
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
709
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
710
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
describe Aquarium::Finders::MethodFinder, "#find (using :options => [:public, :protected, :class, :instance])" do
|
715
|
+
before(:each) do
|
716
|
+
common_before
|
717
|
+
end
|
718
|
+
|
719
|
+
it "should find public and protected instance methods when :public, :protected, :class, and :instance are specified." do
|
720
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => @test_classes, :methods => /test_method/, :options => [:public, :protected, :class, :instance, :suppress_ancestor_methods]
|
721
|
+
actual.matched.size.should == 3
|
722
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
723
|
+
actual.matched[ClassWithPublicClassMethod].should == Set.new([:public_class_test_method])
|
724
|
+
actual.matched[ClassWithProtectedInstanceMethod].should == Set.new([:protected_instance_test_method])
|
725
|
+
actual.not_matched.size.should == 2
|
726
|
+
actual.not_matched[ClassWithPrivateInstanceMethod].should == Set.new([/test_method/])
|
727
|
+
actual.not_matched[ClassWithPrivateClassMethod].should == Set.new([/test_method/])
|
728
|
+
end
|
729
|
+
|
730
|
+
it "should find only public and protected instance methods for objects even when :class is specified along with :public, :protected, :class, and :instance." do
|
731
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => @test_objects, :methods => /test_method/, :options => [:public, :protected, :class, :instance, :suppress_ancestor_methods]
|
732
|
+
actual.matched.size.should == 2
|
733
|
+
actual.matched[@pub].should == Set.new([:public_instance_test_method])
|
734
|
+
actual.matched[@pro].should == Set.new([:protected_instance_test_method])
|
735
|
+
actual.not_matched.size.should == 3
|
736
|
+
actual.not_matched[@pri].should == Set.new([/test_method/])
|
737
|
+
actual.not_matched[@cpub].should == Set.new([/test_method/])
|
738
|
+
actual.not_matched[@cpri].should == Set.new([/test_method/])
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
742
|
+
describe "Aquarium::Finders::MethodFinder#find (looking for singleton methods)" do
|
743
|
+
before(:each) do
|
744
|
+
class Empty
|
745
|
+
end
|
746
|
+
|
747
|
+
@objectWithSingletonMethod = Empty.new
|
748
|
+
class << @objectWithSingletonMethod
|
749
|
+
def a_singleton_method
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
class NotQuiteEmpty
|
754
|
+
end
|
755
|
+
class << NotQuiteEmpty
|
756
|
+
def a_class_singleton_method
|
757
|
+
end
|
758
|
+
end
|
759
|
+
@notQuiteEmpty = NotQuiteEmpty.new
|
760
|
+
end
|
761
|
+
|
762
|
+
it "should find instance-level singleton methods for objects when :singleton is specified." do
|
763
|
+
actual = Aquarium::Finders::MethodFinder.new.find :objects => [@notQuiteEmpty, @objectWithSingletonMethod], :methods => :all, :options => [:singleton]
|
764
|
+
actual.matched.size.should == 1
|
765
|
+
actual.matched[@objectWithSingletonMethod].should == Set.new([:a_singleton_method])
|
766
|
+
actual.not_matched.size.should == 1
|
767
|
+
actual.not_matched[@notQuiteEmpty].should == Set.new([:all])
|
768
|
+
end
|
769
|
+
|
770
|
+
it "should find type-level singleton methods for types when :singleton is specified." do
|
771
|
+
actual = Aquarium::Finders::MethodFinder.new.find :types => [NotQuiteEmpty, Empty], :methods => :all, :options => [:singleton, :suppress_ancestor_methods]
|
772
|
+
actual.matched.size.should == 1
|
773
|
+
actual.matched[NotQuiteEmpty].should == Set.new([:a_class_singleton_method])
|
774
|
+
actual.not_matched.size.should == 1
|
775
|
+
actual.not_matched[Empty].should == Set.new([:all])
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
describe "Aquarium::Finders::MethodFinder#find (looking for methods that end in non-alphanumeric characters)" do
|
780
|
+
class ClassWithFunkyMethodNames
|
781
|
+
def huh?; true; end
|
782
|
+
def yes!; true; end
|
783
|
+
def == other; false; end
|
784
|
+
def =~ other; false; end
|
785
|
+
end
|
786
|
+
|
787
|
+
before(:each) do
|
788
|
+
@funky = ClassWithFunkyMethodNames.new
|
789
|
+
end
|
790
|
+
|
791
|
+
{'?' => :huh?, '!' => :yes!, '=' => :==, '~' => :=~}.each do |char, method|
|
792
|
+
it "should find instance methods for types when searching for names that end with a '#{char}' character using the method's name." do
|
793
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithFunkyMethodNames, :methods => method
|
794
|
+
actual.matched.size.should == 1
|
795
|
+
actual.matched[ClassWithFunkyMethodNames].should == Set.new([method])
|
796
|
+
actual.not_matched.size.should == 0
|
797
|
+
end
|
798
|
+
|
799
|
+
it "should find instance methods for types when searching for names that end with a '#{char}' character using a regular expression." do
|
800
|
+
actual = Aquarium::Finders::MethodFinder.new.find :type => ClassWithFunkyMethodNames, :methods => /#{Regexp.escape(char)}$/
|
801
|
+
actual.matched.size.should >= 1
|
802
|
+
actual.matched[ClassWithFunkyMethodNames].should include(method)
|
803
|
+
actual.not_matched.size.should == 0
|
804
|
+
end
|
805
|
+
|
806
|
+
it "should find instance methods for objects when searching for names that end with a '#{char}' character using the method's name." do
|
807
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => @funky, :methods => method
|
808
|
+
actual.matched.size.should == 1
|
809
|
+
actual.matched[@funky].should == Set.new([method])
|
810
|
+
actual.not_matched.size.should == 0
|
811
|
+
end
|
812
|
+
|
813
|
+
it "should find instance methods for objects when searching for names that end with a '#{char}' character using a regular expression." do
|
814
|
+
actual = Aquarium::Finders::MethodFinder.new.find :object => @funky, :methods => /#{Regexp.escape(char)}$/
|
815
|
+
actual.matched.size.should >= 1
|
816
|
+
actual.matched[@funky].should include(method)
|
817
|
+
actual.not_matched.size.should == 0
|
818
|
+
end
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
describe "Aquarium::Finders::MethodFinder#find_all_by" do
|
823
|
+
it "should accept :all for the methods argument." do
|
824
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by ClassWithPublicInstanceMethod, :all, :suppress_ancestor_methods
|
825
|
+
actual.matched.size.should == 1
|
826
|
+
actual.matched[ClassWithPublicInstanceMethod].should == Set.new([:public_instance_test_method])
|
827
|
+
actual.not_matched.size.should == 0
|
828
|
+
pub = ClassWithPublicInstanceMethod.new
|
829
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by pub, :all, :suppress_ancestor_methods
|
830
|
+
actual.matched.size.should == 1
|
831
|
+
actual.matched[pub].should == Set.new([:public_instance_test_method])
|
832
|
+
actual.not_matched.size.should == 0
|
833
|
+
end
|
834
|
+
|
835
|
+
it "should behave like Aquarium::Finders::MethodFinder#find with an explicit parameter list rather than a hash." do
|
836
|
+
expected = Aquarium::Finders::MethodFinder.new.find :types => ClassWithPrivateInstanceMethod,
|
837
|
+
:methods => /test_method/, :options => [:private, :instance, :suppress_ancestor_methods]
|
838
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by ClassWithPrivateInstanceMethod,
|
839
|
+
/test_method/, :private, :instance, :suppress_ancestor_methods
|
840
|
+
actual.should == expected
|
841
|
+
|
842
|
+
expected = Aquarium::Finders::MethodFinder.new.find :objects => @pub,
|
843
|
+
:methods => /test_method/, :options => [:private, :instance, :suppress_ancestor_methods]
|
844
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by @pub,
|
845
|
+
/test_method/, :private, :instance, :suppress_ancestor_methods
|
846
|
+
actual.should == expected
|
847
|
+
|
848
|
+
expected = Aquarium::Finders::MethodFinder.new.find :types => [ClassWithPublicInstanceMethod, ClassWithPrivateInstanceMethod],
|
849
|
+
:methods => ["foo", /test_method/], :options => [:instance, :suppress_ancestor_methods]
|
850
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by [ClassWithPublicInstanceMethod, ClassWithPrivateInstanceMethod],
|
851
|
+
["foo", /test_method/], :instance, :suppress_ancestor_methods
|
852
|
+
actual.should == expected
|
853
|
+
|
854
|
+
expected = Aquarium::Finders::MethodFinder.new.find :objects => [@pub, @pri],
|
855
|
+
:methods => ["foo", /test_method/], :options => [:instance, :suppress_ancestor_methods]
|
856
|
+
actual = Aquarium::Finders::MethodFinder.new.find_all_by [@pub, @pri],
|
857
|
+
["foo", /test_method/], :instance, :suppress_ancestor_methods
|
858
|
+
actual.should == expected
|
859
|
+
end
|
860
|
+
end
|
861
|
+
|
862
|
+
describe "Aquarium::Finders::MethodFinder.is_recognized_method_option" do
|
863
|
+
|
864
|
+
it "should be true for :public, :private, :protected, :instance, :class, and :suppress_ancestor_methods as strings or symbols." do
|
865
|
+
%w[public private protected instance class suppress_ancestor_methods].each do |s|
|
866
|
+
Aquarium::Finders::MethodFinder.is_recognized_method_option(s).should == true
|
867
|
+
Aquarium::Finders::MethodFinder.is_recognized_method_option(s.to_sym).should == true
|
868
|
+
end
|
869
|
+
end
|
870
|
+
|
871
|
+
it "should be false for unknown options." do
|
872
|
+
%w[public2 wierd unknown string].each do |s|
|
873
|
+
Aquarium::Finders::MethodFinder.is_recognized_method_option(s).should == false
|
874
|
+
Aquarium::Finders::MethodFinder.is_recognized_method_option(s.to_sym).should == false
|
875
|
+
end
|
876
|
+
end
|
877
|
+
end
|
878
|
+
|