[rspec-devel] [Rspec-users] subject.should_be true

David Chelimsky dchelimsky at gmail.com
Mon Oct 16 07:41:55 EDT 2006


On 10/16/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 10/16/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> > On 10/16/06, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> > > On 10/16/06, David Lee <david at davelee.com.au> wrote:
> > > > thanks, Aslak. I read it.
> > > >
> > > > I still think what i first did, which is that .should_be true should
> > > > be more lax than should_equal true.
> > > >
> > >
> > > ri Object.==
> > >
> > > -------------------------------------------------------------- Object#==
> > >      obj == other        => true or false
> > >      obj.equal?(other)   => true or false
> > >      obj.eql?(other)     => true or false
> > > ------------------------------------------------------------------------
> > >      Equality---At the +Object+ level, +==+ returns +true+ only if _obj_
> > >      and _other_ are the same object. Typically, this method is
> > >      overridden in descendent classes to provide class-specific meaning.
> > >
> > >      Unlike +==+, the +equal?+ method should never be overridden by
> > >      subclasses: it is used to determine object identity (that is,
> > >      +a.equal?(b)+ iff +a+ is the same object as +b+).
> > >
> > >      The +eql?+ method returns +true+ if _obj_ and _anObject_ have the
> > >      same value. Used by +Hash+ to test members for equality. For
> > >      objects of class +Object+, +eql?+ is synonymous with +==+.
> > >      Subclasses normally continue this tradition, but there are
> > >      exceptions. +Numeric+ types, for example, perform type conversion
> > >      across +==+, but not across +eql?+, so:
> > >
> > >         1 == 1.0     #=> true
> > >         1.eql? 1.0   #=> false
>
> Actually, now that I think about it, if we're really aligning w/ ruby
> syntax and intent, we should just use the language:
>
> subject.should_equal value passes only if subject.equal? value passes
> subject.should_eql value passes only if subject.eql? value passes
> subect.should == value passes only if subject == value passes
>
> Because RSpec supports arbitrary predicates and operators, we just
> need to remove the special handling of these cases and it will work
> correctly.
>
> Then we have to have the (what I expect to be) unpleasant debate about
> whether to deprecate should_be (which is what I think we should do).

... that is to say should_be with an argument. i.e. we should stop
supporting this:

  subject.should_be value

but we should keep supporthing this:

  subject.should_be_arbitrary_predicate

This would require a BIG FAT warning w/ the release, but it also only
requires a simple search and replace on everyone's specs:

"should_equal" becomes "should_eql" #DO THIS FIRST
"should_be " becomes "should_equal " or "should == "

I realize I'm just spouting out my thoughts as they come to me. That's
because I'm heading in to work at a client where I have limited access
to the world and won't really be able to play again until tonight, so
I'm trying to get all of my cents in before I leave.

I'm not sure where this will land, but I do feel very strongly that
the current situation does not align w/ ruby, is confusing, and needs
to be changed sooner rather than later.

Cheers,
David


More information about the rspec-devel mailing list