Skip to content

Instantly share code, notes, and snippets.

@eproxus
Created March 20, 2013 11:09
Show Gist options
  • Save eproxus/5203893 to your computer and use it in GitHub Desktop.
Save eproxus/5203893 to your computer and use it in GitHub Desktop.
Colorized, formatted output for assert_equal
# Colorized, formatted output for assert_equal
module Test
module Unit
module Assertions
alias_method :assert_equal_original, :assert_equal
def assert_equal(expected, actual, msg = "")
unless expected == actual
require 'ap'
expected_str = pretty_format_object("Expected:".green, expected)
actual_str = pretty_format_object("Actual: ".red, actual)
msg = msg.yellow + "\n" unless msg.empty?
assert false, "#{msg}#{expected_str}\n#{actual_str}"
end
end
private
def pretty_format_object(prefix, obj)
fmt = obj.ai(:indent => -2)
prefix << if fmt.lines.count > 1 then "\n" else " " end
prefix << fmt
end
end
end
end
@eproxus
Copy link
Author

eproxus commented Mar 20, 2013

Screenshots:
Screenshot
Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment