Sha256: 8f8fd2be220694b6c9a0e852eceb26c221b7ea2ad72fa0bd193a8b4a2de45d45

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

require 'rscm/tempdir'
require 'rscm/path_converter'
require 'rscm/difftool'

module RSCM
  module Difftool
    # assertion method that reports differences as diff.
    # useful when comparing big strings
    def assert_equal_with_diff(expected, actual, message="", temp_basedir=File.dirname(__FILE__) + "/../../target")
      diff(expected, actual, temp_basedir) do |diff_io, cmd|
        diff_string = diff_io.read
        if(diff_string.strip != "")
          flunk "#{message}\nThere were differences\ndiff command: #{cmd}\ndiff:\n#{diff_string}"
        end
      end
    end
    module_function :assert_equal_with_diff
  
    def diff(expected, actual, temp_basedir, &block)
      dir = RSCM.new_temp_dir("diff", temp_basedir)

      expected_file = nil
      if(File.exist?(expected))
        expected_file = expected
      else
        expected_file = "#{dir}/expected"
        File.open(expected_file, "w") {|io| io.write(expected)}
      end

      actual_file = "#{dir}/actual"
      File.open(actual_file, "w") {|io| io.write(actual)}

      difftool = WINDOWS ? File.dirname(__FILE__) + "/../../bin/diff.exe" : "diff"
      e = RSCM::PathConverter.filepath_to_nativepath(expected_file, false)
      a = RSCM::PathConverter.filepath_to_nativepath(actual_file, false)
      cmd = "#{difftool} --ignore-space-change #{e} #{a}"
      IO.popen(cmd) do |io|
        yield io, cmd
      end
    end
    module_function :diff

  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
sdague-rscm-0.5.4 lib/rscm/difftool.rb
rscm-0.4.5 lib/rscm/difftool.rb
rscm-0.5.1 lib/rscm/difftool.rb
rscm-0.5.0 lib/rscm/difftool.rb
whistle-0.1 vendor/rscm-0.5.1-patched-stripped/lib/rscm/difftool.rb
whistle-0.1.1 vendor/rscm-0.5.1-patched-stripped/lib/rscm/difftool.rb