Sha256: e091f36686eb359a504b11ed1d1334ae8cf78f1feff829324bb4840c71e24ef9

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

###
### $Rev: 5 $
### $Release: 0.2.0 $
### copyright(c) 2005 kuwata-lab all rights reserved.
###

require 'test/unit'
require 'tempfile'

module Test
   module Unit
      class TestCase
         def assert_equal_with_diff(expected, actual, message=nil, diffopt='-u', flag_cut=true)
            if expected == actual
               assert(true)
               return
            end

            if expected[-1] != ?\n || actual[-1] != ?\n
               expected += "\n"
               actual   += "\n"
            end
            begin
               expfile = Tempfile.new(".expected.")
               expfile.write(expected); expfile.flush()
               actfile = Tempfile.new(".actual.")
               actfile.write(actual);   actfile.flush()
               diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
            ensure
               expfile.close(true) if expfile
               actfile.close(true) if actfile
            end

            # cut 1st & 2nd lines
            message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
            #raise Test::Unit::AssertionFailedError.new(message)
            assert_block(message) { false }  # or assert(false, message)
         end
         #def assert_equal(expected, actual, message=nil)
         #   return assert_equal_with_diff(expected, actual, message)
         #end
      end
   end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kwalify-0.2.0 lib/kwalify/util/assert-diff.rb