[rspec-devel] Failure message for "string".should_equal "string"

George Anderson george at benevolentcode.com
Thu Nov 9 22:05:10 EST 2006

This may be overkill, but bear with me.

should_equal tests for object identity.  Typically when a should_equal
expectation fails, the failure message is straightforward.  For example, "1
should equal 2" is evident.  However, in the case of strings and arrays,
it's not always so clear.  Witness:

"string".should_equal "string"
=> FAILED: "string" should equal "string"

[].should_equal []
=> FAILED: [] should equal []

It may be pandering to the noobs in the crowd (I consider myself well within
their ranks), but it seems the failure message would be more clear if it
included some distinguishing information, such as object_ids.  Something

"string".should_equal "string"
=> FAILED: "string"<object_id: 1587724> should equal "string"<object_id:

[].should_equal []
=> FAILED: []<object_id: 1587744> should equal []<object_id: 1587734>

Granted, it's not elegant/pretty/terse, but the issue at hand is more
obvious.  Adding object_ids may do little more than help the less
experienced among us (ahem) learn more quickly the distinction between
should_equal, should_eql, and should ==, hence my initial "overkill"
comment.  Having gone through the exercise of hacking (truly) together
support for this, I've now clearly gotten this distinction.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20061109/a507b244/attachment.html 

More information about the rspec-devel mailing list