Sha256: 3e3ca92aae8d33a4f516aae870c12a23169427e6bb39aedb1522f126906b2e36

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

require 'test/unit'
require 'rscm/tempdir'
require 'rscm/path_converter'

module Test
  module Unit
    class TestCase
      # assertion method that reports differences as diff.
      # useful when comparing big strings
      def assert_equal_with_diff(expected, actual)
        dir = RSCM.new_temp_dir("diff")
        
        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|
          diff = io.read
          assert_equal("", diff, diff)
        end
      end
    end
  end
end

module RSCM
  class DiffPersisterTest < Test::Unit::TestCase
    def test_diffing_fails_with_diff_when_different
      assert_raises(Test::Unit::AssertionFailedError) {
        assert_equal_with_diff("This is a\nmessage with\nsome text", "This is a\nmessage without\nsome text")
      }
    end

    def test_diffing_passes_with_diff_when_equal
      assert_equal_with_diff("This is a\nmessage with\nsome text", "This is a\nmessage with\nsome text")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rscm-0.1.0.999 test/rscm/difftool_test.rb
rscm-0.1.0.1337 test/rscm/difftool_test.rb
rscm-0.1.0.1338 test/rscm/difftool_test.rb
rscm-0.2.0 test/rscm/difftool_test.rb
rscm-0.1.0 test/rscm/difftool_test.rb
rscm-0.2.1.1404 test/rscm/difftool_test.rb