Module | RSCM::Difftool |
In: |
lib/rscm/difftool.rb
|
assertion method that reports differences as diff. useful when comparing big strings
# File lib/rscm/difftool.rb, line 9 9: def assert_equal_with_diff(expected, actual, message="", temp_basedir=File.dirname(__FILE__) + "/../../target") 10: diff(expected, actual, temp_basedir) do |diff_io, cmd| 11: diff_string = diff_io.read 12: if(diff_string.strip != "") 13: flunk "#{message}\nThere were differences\ndiff command: #{cmd}\ndiff:\n#{diff_string}" 14: end 15: end 16: end
# File lib/rscm/difftool.rb, line 19 19: def diff(expected, actual, temp_basedir, &block) 20: dir = RSCM.new_temp_dir("diff", temp_basedir) 21: 22: expected_file = nil 23: if(File.exist?(expected)) 24: expected_file = expected 25: else 26: expected_file = "#{dir}/expected" 27: File.open(expected_file, "w") {|io| io.write(expected)} 28: end 29: 30: actual_file = "#{dir}/actual" 31: File.open(actual_file, "w") {|io| io.write(actual)} 32: 33: difftool = WINDOWS ? File.dirname(__FILE__) + "/../../bin/diff.exe" : "diff" 34: e = RSCM::PathConverter.filepath_to_nativepath(expected_file, false) 35: a = RSCM::PathConverter.filepath_to_nativepath(actual_file, false) 36: cmd = "#{difftool} --ignore-space-change #{e} #{a}" 37: IO.popen(cmd) do |io| 38: yield io, cmd 39: end 40: end