Class | Spec::Expectations::Differs::Default |
In: |
vendor/plugins/rspec/lib/spec/expectations/differs/default.rb
|
Parent: | Object |
TODO add some rdoc
# File vendor/plugins/rspec/lib/spec/expectations/differs/default.rb, line 15 15: def initialize(options) 16: @options = options 17: end
# File vendor/plugins/rspec/lib/spec/expectations/differs/default.rb, line 51 51: def diff_as_object(target,expected) 52: diff_as_string(PP.pp(target,""), PP.pp(expected,"")) 53: end
This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
# File vendor/plugins/rspec/lib/spec/expectations/differs/default.rb, line 20 20: def diff_as_string(data_new, data_old) 21: data_old = data_old.split(/\n/).map! { |e| e.chomp } 22: data_new = data_new.split(/\n/).map! { |e| e.chomp } 23: output = "" 24: diffs = Diff::LCS.diff(data_old, data_new) 25: return output if diffs.empty? 26: oldhunk = hunk = nil 27: file_length_difference = 0 28: diffs.each do |piece| 29: begin 30: hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines, 31: file_length_difference) 32: file_length_difference = hunk.file_length_difference 33: next unless oldhunk 34: # Hunks may overlap, which is why we need to be careful when our 35: # diff includes lines of context. Otherwise, we might print 36: # redundant lines. 37: if (context_lines > 0) and hunk.overlaps?(oldhunk) 38: hunk.unshift(oldhunk) 39: else 40: output << oldhunk.diff(format) 41: end 42: ensure 43: oldhunk = hunk 44: output << "\n" 45: end 46: end 47: #Handle the last remaining hunk 48: output << oldhunk.diff(format) << "\n" 49: end