[rspec-devel] new handling of equality

David Chelimsky dchelimsky at gmail.com
Tue Oct 17 00:01:41 EDT 2006


Based mostly on the earlier thread on "should_be", we have introduced
a new branch called should_be_working_like_ruby with the new proposed
handling for equality.

Per the CHANGES file in that branch (rev 896):


This release changes the way RSpec handles equality. Previous releases
tried to handle equality
based on the way the words read, rather than the way ruby actually
handles equality. So,
with this release and going forward:

* actual.should_equal(expected) will pass if actual.equal?(expected)
returns true
* actual.should_eql(expected) will pass if actual.eql?(expected) returns true
* actual.should == expected will pass if actual == expected) returns true

At the high level, eql? implies equivalence, while equal? implies
object identity. For more
information on how ruby deals w/ equality, you should do this:

ri equal?

or look at this:


Also, we left in should_be as a synonym for should_equal, so the only
specs that should break are the
ones using should_equal (which used to use <code>==</code> instead of

Lastly, should_be used to handle true and false differently from any
other values. We've removed
this special handling, so now actual.should_be true will fail for any
value other than true (it
used to pass for any non-nil, non-false value), and actual.should_be
false will fail for any
value other than false (it used to pass for nil or false).

Here's what you'll need to do to update your specs:
1. search for "should_equal" and replace with "should_eql"
2. run specs

If any specs still fail, they are probably related to should_be(true)
or should_be(false) using
non-boolean values. Those you'll just have to inspect manually and
adjust appropriately (sorry!).

There are two outstanding issues.

1. actual.should != expected does not work (right now you can use
2. lambda { expr }.should_eql expected compares to the proc rather
than the result

I'll bring these up in separate threads, so please don't respond to
this thread w/ either of these issues.

I'd encourage any and all of you who can check out and build from
source to check out and build this branch and let us know what other
issues you encounter. We'll be releasing this soon, and would like to
make the transition from 0.6.x to 0.7.0 as smooth as possible for all.


More information about the rspec-devel mailing list