diff options
author | Luke Kanies <luke@madstop.com> | 2007-08-23 11:52:31 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-08-23 11:52:31 -0500 |
commit | 58494cc8566da04711715e54274f472377b1aba0 (patch) | |
tree | 66bd610d359f549fc68e9985accf7b4141b7982e /test/lib/spec/expectations/differs/default.rb | |
parent | d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e (diff) | |
download | puppet-58494cc8566da04711715e54274f472377b1aba0.tar.gz puppet-58494cc8566da04711715e54274f472377b1aba0.tar.xz puppet-58494cc8566da04711715e54274f472377b1aba0.zip |
Building a stand-alone spec directory for creating the new spec-based tests.
Diffstat (limited to 'test/lib/spec/expectations/differs/default.rb')
-rw-r--r-- | test/lib/spec/expectations/differs/default.rb | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/test/lib/spec/expectations/differs/default.rb b/test/lib/spec/expectations/differs/default.rb deleted file mode 100644 index 87e59b3a6..000000000 --- a/test/lib/spec/expectations/differs/default.rb +++ /dev/null @@ -1,61 +0,0 @@ -begin - require 'rubygems' - require 'diff/lcs' #necessary due to loading bug on some machines - not sure why - DaC - require 'diff/lcs/hunk' -rescue LoadError ; raise "You must gem install diff-lcs to use diffing" ; end - -require 'pp' - -module Spec - module Expectations - module Differs - - # TODO add some rdoc - class Default - def initialize(format=:unified,context_lines=nil,colour=nil) - - context_lines ||= 3 - colour ||= false - - @format,@context_lines,@colour = format,context_lines,colour - end - - # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool) - def diff_as_string(data_old, data_new) - data_old = data_old.split(/\n/).map! { |e| e.chomp } - data_new = data_new.split(/\n/).map! { |e| e.chomp } - output = "" - diffs = Diff::LCS.diff(data_old, data_new) - return output if diffs.empty? - oldhunk = hunk = nil - file_length_difference = 0 - diffs.each do |piece| - begin - hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @context_lines, - file_length_difference) - file_length_difference = hunk.file_length_difference - next unless oldhunk - # Hunks may overlap, which is why we need to be careful when our - # diff includes lines of context. Otherwise, we might print - # redundant lines. - if (@context_lines > 0) and hunk.overlaps?(oldhunk) - hunk.unshift(oldhunk) - else - output << oldhunk.diff(@format) - end - ensure - oldhunk = hunk - output << "\n" - end - end - #Handle the last remaining hunk - output << oldhunk.diff(@format) << "\n" - end - - def diff_as_object(target,expected) - diff_as_string(PP.pp(target,""), PP.pp(expected,"")) - end - end - end - end -end |