Module: RSCM::Difftool

Defined in:
lib/rscm/difftool.rb

Class Method Summary collapse

Class Method Details

.assert_equal_with_diff(expected, actual, 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
# File 'lib/rscm/difftool.rb', line 9

def assert_equal_with_diff(expected, actual, temp_basedir=File.dirname(__FILE__) + "/../../target")
  diff(expected, actual, temp_basedir) do |diff_io|
    diff_string = diff_io.read
    assert_equal("", diff_string, diff_string)
  end
end

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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rscm/difftool.rb', line 17

def diff(expected, actual, temp_basedir, &block)
  dir = RSCM.new_temp_dir("diff", temp_basedir)

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

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