Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/differ.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/differ.rb 62 50
32.26%
26.00%

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 'diff/lcs'
2 require 'diff/lcs/hunk'
3 require 'pp'
4 
5 module RSpec
6   module Expectations
7     class Differ
8       def initialize(ignore=nil)
9       end
10 
11       # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
12       def diff_as_string(data_new, data_old)
13         data_old = data_old.split(/\n/).map! { |e| e.chomp }
14         data_new = data_new.split(/\n/).map! { |e| e.chomp }
15         output = ""
16         diffs = Diff::LCS.diff(data_old, data_new)
17         return output if diffs.empty?
18         oldhunk = hunk = nil  
19         file_length_difference = 0
20         diffs.each do |piece|
21           begin
22             hunk = Diff::LCS::Hunk.new(
23               data_old, data_new, piece, context_lines, file_length_difference
24             )
25             file_length_difference = hunk.file_length_difference      
26             next unless oldhunk      
27             # Hunks may overlap, which is why we need to be careful when our
28             # diff includes lines of context. Otherwise, we might print
29             # redundant lines.
30             if (context_lines > 0) and hunk.overlaps?(oldhunk)
31               hunk.unshift(oldhunk)
32             else
33               output << oldhunk.diff(format)
34             end
35           ensure
36             oldhunk = hunk
37             output << "\n"
38           end
39         end  
40         #Handle the last remaining hunk
41         output << oldhunk.diff(format) << "\n"
42       end  
43 
44       def diff_as_object(actual,expected)
45         actual = String === actual ? actual : PP.pp(actual,"")
46         expected = String === expected ? expected : PP.pp(expected,"")
47         diff_as_string(actual, expected)
48       end
49 
50     protected
51 
52       def format
53         :unified
54       end
55 
56       def context_lines
57         3
58       end
59     end
60 
61   end
62 end

Generated on Fri Apr 22 17:22:41 -0700 2011 with rcov 0.9.8