Module: RSCM::Difftool

Defined in:
lib/rscm/difftool.rb

Class Method Summary collapse

Class Method Details

.assert_equal_with_diff(expected, actual, message = "", temp_basedir = File.dirname(__FILE__) + "/../../target") ⇒ Object

assertion method that reports differences as diff. useful when comparing big strings



9
10
11
12
13
14
15
16
# File 'lib/rscm/difftool.rb', line 9

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

.diff(expected, actual, temp_basedir, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rscm/difftool.rb', line 19

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