Created
March 20, 2013 11:09
-
-
Save eproxus/5203893 to your computer and use it in GitHub Desktop.
Colorized, formatted output for assert_equal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshots: