[rspec-users] got/expects causes mental layering violation

Jay Levitt lists-rspec at shopwatch.org
Thu Aug 2 09:57:40 EDT 2007

I was, for the first time, spec'ing a class that redefined ==.  And my 
spec was incorrect, so == was returning false.

The result was something like:

class C
   def ==(other)

.. C.new.should == other...

expected other, got #<C:0x7f03c454> (using ==)

But wait!  Why on earth is == returning the class itself instead of 
true/false?  That shouldn't be possible.  No, no time for coffee, let me 
go debug this for a few hours... oh.  of course.  == IS returning a 
boolean value, in this case, false; rspec is helpfully showing me 
C.inspect so I can see why they MIGHT differ, assuming I haven't 
redefined ==.  Which I have.

Would it be good, when == is redefined (or eql? or equals?) for the 
rspec output to indicate somehow what it's doing and why you might be 
seeing what you're seeing?  Maybe something like

expected C==other, but C!=other.  You have redefined ==.  C.inspect 
shows: #<C:...>

but much prettier and better worded.

Or do I just call this a learning experience?


More information about the rspec-users mailing list