Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/runner/differs/default.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/runner/differs/default.rb 93 74
24.73%
21.62%

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 require 'spec/runner/differs/load-diff-lcs'
2 require 'pp'
3 
4 module Spec
5   module Expectations
6     module Differs
7       unless defined?(Spec::Expectations::Differs::Default)
8         class Default
9           def initialize(options)
10             @options = options
11           end
12 
13           # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
14           def diff_as_string(data_new, data_old)
15             data_old = data_old.split(/\n/).map! { |e| e.chomp }
16             data_new = data_new.split(/\n/).map! { |e| e.chomp }
17             output = ""
18             diffs = Diff::LCS.diff(data_old, data_new)
19             return output if diffs.empty?
20             oldhunk = hunk = nil  
21             file_length_difference = 0
22             diffs.each do |piece|
23               begin
24                 hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
25                                            file_length_difference)
26                 file_length_difference = hunk.file_length_difference      
27                 next unless oldhunk      
28                 # Hunks may overlap, which is why we need to be careful when our
29                 # diff includes lines of context. Otherwise, we might print
30                 # redundant lines.
31                 if (context_lines > 0) and hunk.overlaps?(oldhunk)
32                   hunk.unshift(oldhunk)
33                 else
34                   output << oldhunk.diff(format)
35                 end
36               ensure
37                 oldhunk = hunk
38                 output << "\n"
39               end
40             end  
41             #Handle the last remaining hunk
42             output << oldhunk.diff(format) << "\n"
43           end  
44 
45           def diff_as_object(target,expected)
46             diff_as_string(PP.pp(target,""), PP.pp(expected,""))
47           end
48           
49           def diff_as_hash(target, expected)
50             contains_hash = false
51             contains_array = false
52             
53             extra_expected_keys = expected.keys - target.keys
54             extra_target_keys = target.keys - expected.keys
55             
56             o = "\n"
57             
58             o << "Expected hash contains keys that target hash does not: " << extra_expected_keys.inspect << "\n" if !extra_expected_keys.empty?
59             o << "Target hash contains keys that expected hash does not: " << extra_target_keys.inspect << "\n" if !extra_target_keys.empty?
60             
61             expected.delete_if do |key, value|
62               contains_hash = true if value.is_a?(Hash)
63               contains_array = true if value.is_a?(Array)
64               target[key]  == value
65             end
66             
67             expected.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
68               o << "Expected the key #{key.inspect} to be #{expected[key].inspect}, but was #{target[key].inspect}\n"
69             end
70             
71             o << "\n"
72 
73             if contains_hash || contains_array
74               o << diff_as_object(target, expected)
75             else
76               o
77             end
78           end
79 
80           protected
81           def format
82             @options.diff_format
83           end
84 
85           def context_lines
86             @options.context_lines
87           end
88         end
89 
90       end
91     end
92   end
93 end

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