Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/match_array.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/match_array.rb 71 43
57.75%
34.88%

Key

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.

Coverage Details

1 module Spec
2   module Matchers
3 
4     class MatchArray #:nodoc:
5       include Spec::Matchers::Pretty
6       
7       def initialize(expected)
8         @expected = expected
9       end
10 
11       def matches?(actual)
12         @actual = actual        
13         @extra_items = difference_between_arrays(@actual, @expected)
14         @missing_items = difference_between_arrays(@expected, @actual)
15         @extra_items.empty? & @missing_items.empty?
16       end
17 
18       def failure_message_for_should
19         message =  "expected collection contained:  #{safe_sort(@expected).inspect}\n"
20         message += "actual collection contained:    #{safe_sort(@actual).inspect}\n"
21         message += "the missing elements were:      #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty?
22         message += "the extra elements were:        #{safe_sort(@extra_items).inspect}\n"   unless @extra_items.empty?
23         message
24       end
25       
26       def failure_message_for_should_not
27         "Matcher does not support should_not"
28       end
29       
30       def description
31         "contain exactly #{_pretty_print(@expected)}"
32       end
33 
34       private
35 
36         def safe_sort(array)
37           array.all?{|item| item.respond_to?(:<=>)} ? array.sort : array
38         end
39 
40         def difference_between_arrays(array_1, array_2)
41           difference = array_1.dup
42           array_2.each do |element|
43             if index = difference.index(element)
44               difference.delete_at(index)
45             end
46           end
47           difference
48         end
49 
50 
51     end
52 
53     # :call-seq:
54     #   should =~ expected
55     #
56     # Passes if actual contains all of the expected regardless of order. 
57     # This works for collections. Pass in multiple args  and it will only 
58     # pass if all args are found in collection.
59     #
60     # NOTE: there is no should_not version of array.should =~ other_array
61     # 
62     # == Examples
63     #
64     #   [1,2,3].should   =~ [1,2,3]   # => would pass
65     #   [1,2,3].should   =~ [2,3,1]   # => would pass
66     #   [1,2,3,4].should =~ [1,2,3]   # => would fail
67     #   [1,2,2,3].should =~ [1,2,3]   # => would fail
68     #   [1,2,3].should   =~ [1,2,3,4] # => would fail
69     OperatorMatcher.register(Array, '=~', Spec::Matchers::MatchArray)
70   end
71 end

Generated on Mon May 10 23:40:27 -0700 2010 with rcov 0.9.8