lib/ae/assertor.rb in ae-1.7.1 vs lib/ae/assertor.rb in ae-1.7.2
- old
+ new
@@ -1,7 +1,8 @@
require 'ae/assertion'
require 'ae/basic_object'
+require 'ansi/diff'
module AE
# Assertor is the underlying class of the whole system. It implements
# the flutent assertion notation.
@@ -69,11 +70,11 @@
end
# The intent of the method is to raise an assertion failure
# class that the test framework supports.
def self.raise_assertion(error, negated, backtrace=nil)
- if not Exception === error
+ if not ::Exception === error
error = assertion_error.new(error)
end
error.set_negative(negated)
error.set_backtrace(backtrace || caller)
error.set_assertion(true)
@@ -305,26 +306,38 @@
end
COMPARISON_OPERATORS = { :"==" => :"!=" }
# Message to use when making a comparion assertion.
+ #
+ # NOTE: This message utilizes the ANSI gem to produce colorized
+ # comparisons. If you need to remove color output (for non-ANSI
+ # terminals) you can either set `AE.ansi = false` or use the
+ # ANSI library's master switch to deactive all ANSI codes,
+ # which can be set in your test helper.
+ #
+ # @see http://rubyworks.github.com/ansi
def compare_message(operator, *args, &blk)
return nil unless COMPARISON_OPERATORS.key?(operator)
prefix = ""
- a, b = @delegate, args.first
+ a, b = @delegate.inspect, args.first.inspect
if @negated
op = COMPARISON_OPERATORS[operator]
if op
operator = op
else
prefix = "NOT "
end
end
+ if AE.ansi?
+ diff = ::ANSI::Diff.new(a,b)
+ a = diff.diff1
+ b = diff.diff2
+ end
if a.size > 13 or b.size > 13
- diff = ANSI::Diff.new(a,b)
- prefix + "a #{operator} b\na) " + diff.diff1 + "\nb) " + diff.diff2
+ prefix + "a #{operator} b\na) " + a + "\nb) " + b
else
- prefix + "#{a.inspect} #{operator} #{b.inspect}"
+ prefix + "#{a} #{operator} #{b}"
end
end
# Puts together a suitable error message.
#