Currently, ruby's assert_equal compares the objects by calling
expected == actual
That's usually okay, but if you've defined a custom "==" method you'd have problems.
Example:
class Error
attr_reader :id, :msg
def initialize(id, :msg)
@id = id
end
def ==(other)
case other
when self.class
self.id == other.id
when Symbol
self.id == other
else
self.msg == other.to_s
end
end
end
# then inside a test
# ....
def test_equality_with_id
foo = SomeFooness.new(:empty, "can't be empty")
assert_equal :empty, foo
end
def test_equality_with_message
foo = SomeFooness.new(:empty, "can't be empty")
assert_equal "can't be empty", foo
end
Without this patch, those tests would fail since assert_equal would call:
:empty == foo
# and
"can't be empty" == foo
While what you want is:
foo == :empty
# and
foo == "can't be empty"
This patchs override assert_equal to test the opposite:
actual == expected