Module: Test::Unit::AssertionsWithDiff

Included in:
TestCase
Defined in:
lib/test-unit-ext/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_equal(expected, actual, message = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/test-unit-ext/assertions.rb', line 6

def assert_equal(expected, actual, message=nil)
  super
rescue AssertionFailedError
  expected = PP.pp(expected, "") unless expected.is_a?(String)
  actual = PP.pp(actual, "") unless actual.is_a?(String)
  diff = Diff.readable(expected, actual)
  if /^[\?\-\+].{79}/ =~ diff
    folded_diff = Diff.readable(fold(expected), fold(actual))
    diff = "#{diff}\n\nfolded diff:\n#{folded_diff}"
  end
  raise $!, "#{$!.message}\n\ndiff:\n#{diff}", $@
end

#fold(string) ⇒ Object



19
20
21
22
23
# File 'lib/test-unit-ext/assertions.rb', line 19

def fold(string)
  string.split(/\n/).collect do |line|
    line.gsub(/(.{78})/, "\\1\n")
  end.join("\n")
end