Forum: RSpec eql not matching identical hashes unless they actually are the same object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Leandro P. (Guest)
on 2009-01-14 11:18
(Received via mailing list)
rspec 1.1.11 and it's rails sidekick.

After writing a few specs for an object I created that inherits form
an Hash I noticed that eql wasn't matching hashes that where actually
matching (I'm pretty sure it worked fine before):

  {:foo => 0, :bar => 1}.should eql({:foo => 0, :bar => 1})
  # => expected {:foo=>0, :bar=>1}, got {:foo=>0, :bar=>1}
(using .eql?)

  h={:foo => 0, :bar => 1}
  h.should eql(h)
  # => pass

by the way == still works:
  ({:foo => 0, :bar => 1} == {:foo => 0, :bar => 1}).should
  # => Still passes

It works ok with everything else...
I obviously did something wrong. Any clue? Where should I look?

Cheers
Aslak H. (Guest)
on 2009-01-14 13:19
(Received via mailing list)
On Thu, Jan 8, 2009 at 5:26 PM, Leandro P. 
<removed_email_address@domain.invalid>
wrote:

>  h={:foo => 0, :bar => 1}
>  h.should eql(h)
>  # => pass
>
> by the way == still works:
>  ({:foo => 0, :bar => 1} == {:foo => 0, :bar => 1}).should
>  # => Still passes
>
> It works ok with everything else...
> I obviously did something wrong. Any clue? Where should I look?
>

http://rspec.rubyforge.org/rspec/1.1.12/classes/Sp...

Also - read up on Ruby's semantics of eql?, equal? and ==
http://letmegooglethatforyou.com/?q=ruby+eql%3F+eq...

:-)
Maurício L. (Guest)
on 2009-01-14 14:18
(Received via mailing list)
"eql?" matches object references, you should use "==" to match equality.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
David C. (Guest)
on 2009-01-14 17:47
(Received via mailing list)
On Wed, Jan 14, 2009 at 5:07 AM, Maurício Linhares
<removed_email_address@domain.invalid> wrote:
> "eql?" matches object references, you should use "==" to match equality.

eql? acts differently in different situations. equal? is the one you
should use for object references if you want any consistency.
This topic is locked and can not be replied to.