C0 code coverage information
Generated on Mon Aug 13 01:18:53 -0400 2007 with rcov 0.8.0
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.
1 begin
2 require 'rubygems'
3 require 'diff/lcs' #necessary due to loading bug on some machines - not sure why - DaC
4 require 'diff/lcs/hunk'
5 rescue LoadError ; raise "You must gem install diff-lcs to use diffing" ; end
6
7 require 'pp'
8
9 module Spec
10 module Expectations
11 module Differs
12
13 # TODO add some rdoc
14 class Default
15 def initialize(format=:unified,context_lines=nil,colour=nil)
16
17 context_lines ||= 3
18 colour ||= false
19
20 @format,@context_lines,@colour = format,context_lines,colour
21 end
22
23 # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
24 def diff_as_string(data_old, data_new)
25 data_old = data_old.split(/\n/).map! { |e| e.chomp }
26 data_new = data_new.split(/\n/).map! { |e| e.chomp }
27 output = ""
28 diffs = Diff::LCS.diff(data_old, data_new)
29 return output if diffs.empty?
30 oldhunk = hunk = nil
31 file_length_difference = 0
32 diffs.each do |piece|
33 begin
34 hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @context_lines,
35 file_length_difference)
36 file_length_difference = hunk.file_length_difference
37 next unless oldhunk
38 # Hunks may overlap, which is why we need to be careful when our
39 # diff includes lines of context. Otherwise, we might print
40 # redundant lines.
41 if (@context_lines > 0) and hunk.overlaps?(oldhunk)
42 hunk.unshift(oldhunk)
43 else
44 output << oldhunk.diff(@format)
45 end
46 ensure
47 oldhunk = hunk
48 output << "\n"
49 end
50 end
51 #Handle the last remaining hunk
52 output << oldhunk.diff(@format) << "\n"
53 end
54
55 def diff_as_object(target,expected)
56 diff_as_string(PP.pp(target,""), PP.pp(expected,""))
57 end
58 end
59 end
60 end
61 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.