C0 code coverage information

Generated on Sun Oct 26 11:18:12 -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.
Name Total lines Lines of code Total coverage Code coverage
spec/aquarium/finders/finder_result_spec.rb 417 356
100.0% 
100.0% 
  1 require File.dirname(__FILE__) + '/../spec_helper'
  2 require 'aquarium/spec_example_types'
  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.should be_empty
 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 == 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 be_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 be_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 be_eql(result1)
184     result.should be_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 be_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 be_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 describe Aquarium::Finders::FinderResult, "#|" do
212   it_should_behave_like "union of finder results"
213 
214   it "should support operator-style semantics" do
215     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
216     result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
217     result3 = Aquarium::Finders::FinderResult.new :c => [:c1, :c2]
218     result123a = (result1 | result2) | result3
219     result123b = result1 | (result2 | result3)
220     result123a.should be_eql(result123b)
221   end    
222 end
223 
224 describe "intersection of finder results", :shared => true do
225   it "should return an empty FinderResult if self is empty." do
226     result1 = Aquarium::Finders::FinderResult.new
227     result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
228     result = result1.and result2
229     result.should be_eql(result1)
230   end
231   
232   it "should return an empty FinderResult if the second FinderResult is empty." do
233     result1 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
234     result2 = Aquarium::Finders::FinderResult.new
235     result = result1.and result2
236     result.should be_eql(result2)
237   end
238   
239   it "should return an empty FinderResult if there is no overlap between the two FinderResults." do
240     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b3, :c => :c1}, :a => [:a1, :a2]
241     result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
242     result = result1.and result2
243     result.matched.should     be_empty
244     result.not_matched.should be_empty
245   end    
246 
247   it "should return a FinderResult that is the intersection of self and the second FinderResult." do
248     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
249     result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
250     result = result1.and result2
251     result.matched.should     == {:a => Set.new([:a1])}
252     result.not_matched.should == {:b => Set.new([:b1])}
253   end    
254   
255   it "should be unitary." do
256     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
257     result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
258     result = result1.and result2
259     result.should be_eql(result1)
260     result.should be_eql(result2)
261   end    
262 
263   it "should be commutative." do
264     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
265     result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
266     result12 = result1.and result2
267     result21 = result2.and result1
268     result12.should be_eql(result21)
269   end    
270 
271   it "should be associative." do
272     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => :b1, :c => :c1}, :a => [:a1, :a2]
273     result2 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1, :b2]}, :a => [:a1]
274     result3 = Aquarium::Finders::FinderResult.new :not_matched => {:b => [:b1]}, :a => [:a1]
275     result123a = (result1.and result2).and result3
276     result123b = result1.and(result2.and(result3))
277     result123a.should be_eql(result123b)
278   end    
279 end
280 
281 describe Aquarium::Finders::FinderResult, "#intersection" do
282   it_should_behave_like "intersection of finder results"
283 end
284 describe Aquarium::Finders::FinderResult, "#and" do
285   it_should_behave_like "intersection of finder results"
286 end
287 describe Aquarium::Finders::FinderResult, "#&" do
288   it_should_behave_like "union of finder results"
289 
290   it "should support operator-style semantics" do
291     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:b => 'b', :c => 'c'}, :a => [:a1, :a2]
292     result2 = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
293     result3 = Aquarium::Finders::FinderResult.new :c => [:c1, :c2]
294     result123a = (result1 & result2) & result3
295     result123b = result1 & (result2 & result3)
296     result123a.should be_eql(result123b)
297   end    
298 end
299 
300 
301 describe "subtraction of finder results", :shared => true do
302   it "should return an empty FinderResult if self is substracted from itself." do
303     result = Aquarium::Finders::FinderResult.new :b => [:b1, :b2]
304     (result - result).should be_empty
305   end
306 
307   it "should not be associative" do
308     result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2], :not_matched => {:c => [:c1, :c2]}
309     result2 = Aquarium::Finders::FinderResult.new :a => [:a1]
310     result3 = Aquarium::Finders::FinderResult.new :not_matched => {:c => [:c1]}
311     result123a = (result1 - result2) - result3
312     result123b = result1 - (result2 - result3)
313     result123a.should_not be_eql(result123b)
314   end    
315 end
316 
317 describe Aquarium::Finders::FinderResult, "#minus" do
318   it_should_behave_like "subtraction of finder results"
319 end
320 describe Aquarium::Finders::FinderResult, "#-" do
321   it_should_behave_like "subtraction of finder results"
322 
323   it "should support operator-style semantics" do
324     result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2], :not_matched => {:c => [:c1, :c2]}
325     result2 = Aquarium::Finders::FinderResult.new :b => [:b1]
326     result3 = Aquarium::Finders::FinderResult.new :not_matched => {:c => [:c1]}
327     result123a = (result1 - result2) - result3
328     result123b = result1 - (result2 - result3)
329     result123a.should_not be_eql(result123b)
330   end    
331 end
332 
333 
334 describe Aquarium::Finders::FinderResult, "#.append_matched" do
335   it "should not change self, if no arguments are specified." do
336     result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
337     result1.append_matched 
338     result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
339   end
340 
341   it "should return the appended data when used with an empty finder result." do
342     result1 = Aquarium::Finders::FinderResult.new
343     result1.append_matched :a => [:a1, :a2], :b => [:b1, :b2]
344     result1.matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
345   end
346   
347   it "should append the input hash to the corresponding keys and values." do
348     result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
349     result1.append_matched :a => [:a3, :a4], :b => [:b3], :c => [:c1, :c2]
350     result1.matched.should == {:a => Set.new([:a1, :a2, :a3, :a4]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1, :c2])}
351   end
352 
353   it "should accept single hash values as well as arrays of values." do
354     result1 = Aquarium::Finders::FinderResult.new :a => [:a1, :a2], :b => [:b1, :b2]
355     result1.append_matched :a => :a3, :b => :b3, :c => :c1
356     result1.matched.should == {:a => Set.new([:a1, :a2, :a3]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1])}
357   end
358 end
359 
360 describe Aquarium::Finders::FinderResult, "#.append_not_matched" do
361   it "should not change self, by default." do
362     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:a => [:a1, :a2], :b => [:b1, :b2]}
363     result1.append_not_matched
364     result1.not_matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
365   end
366 
367   it "should work with a default (empty) result." do
368     result1 = Aquarium::Finders::FinderResult.new
369     result1.append_not_matched :a => [:a1, :a2], :b => [:b1, :b2]
370     result1.not_matched.should == {:a => Set.new([:a1, :a2]), :b => Set.new([:b1, :b2])}
371   end
372 
373   it "should append the input hash to the corresponding keys and values." do
374     result1 = Aquarium::Finders::FinderResult.new :not_matched => {:a => [:a1, :a2], :b => [:b1, :b2]}
375     result1.append_not_matched :a => [:a3, :a4], :b => [:b3], :c => [:c1, :c2]
376     result1.not_matched.should == {:a => Set.new([:a1, :a2, :a3, :a4]), :b => Set.new([:b1, :b2, :b3]), :c => Set.new([:c1, :c2])}
377   end
378 end
379 
380 describe "equality", :shared => true do
381   it "should return true for the same object." do
382     result = Aquarium::Finders::FinderResult.new
383     result.should be_eql(result)
384   end
385 
386   it "should return true for two default objects." do
387     result1 = Aquarium::Finders::FinderResult.new
388     result2 = Aquarium::Finders::FinderResult.new
389     result1.should be_eql(result2)
390   end
391 
392   it "should return false for two different objects that are equal and map to the same method." do
393     result1 = Aquarium::Finders::FinderResult.new ExampleParentClass.new => :a
394     result2 = Aquarium::Finders::FinderResult.new ExampleParentClass.new => :a
395     result1.should_not eql(result2)
396   end
397 
398   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
399     result1 = Aquarium::Finders::FinderResult.new :a => 'a',   :not_matched => {:b => 'b'}
400     result2 = Aquarium::Finders::FinderResult.new :a => ['a'], :not_matched => {:b => ['b']}
401     result1.should be_eql(result2)
402   end
403 
404   it "should return false for two objects that are different." do
405     result1 = Aquarium::Finders::FinderResult.new :a => 'a'
406     result2 = Aquarium::Finders::FinderResult.new :b => 'b'
407     result1.should_not eql(result2)
408   end
409 end
410 
411 describe Aquarium::Finders::FinderResult, "#eql?" do
412   it_should_behave_like "equality"
413 end
414 
415 describe Aquarium::Finders::FinderResult, "#==" do
416   it_should_behave_like "equality"
417 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.

Valid XHTML 1.0! Valid CSS!