Leandro Pedroni
2009-Jan-08 16:26 UTC
[rspec-users] eql not matching identical hashes unless they actually are the same object
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
MaurĂcio Linhares
2009-Jan-14 11:07 UTC
[rspec-users] eql not matching identical hashes unless they actually are the same object
"eql?" matches object references, you should use "==" to match equality. - Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Thu, Jan 8, 2009 at 1:26 PM, Leandro Pedroni <ilpoldo at gmail.com> wrote:> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
aslak hellesoy
2009-Jan-14 11:08 UTC
[rspec-users] eql not matching identical hashes unless they actually are the same object
On Thu, Jan 8, 2009 at 5:26 PM, Leandro Pedroni <ilpoldo at gmail.com> wrote:> 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? >http://rspec.rubyforge.org/rspec/1.1.12/classes/Spec/Matchers.html#M000468 Also - read up on Ruby''s semantics of eql?, equal? and =http://letmegooglethatforyou.com/?q=ruby+eql%3F+equal%3F+%3D%3D :-)> > Cheers > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090114/288995bd/attachment.html>
David Chelimsky
2009-Jan-14 15:45 UTC
[rspec-users] eql not matching identical hashes unless they actually are the same object
On Wed, Jan 14, 2009 at 5:07 AM, Maur?cio Linhares <mauricio.linhares at gmail.com> 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.> > - > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) > > > > On Thu, Jan 8, 2009 at 1:26 PM, Leandro Pedroni <ilpoldo at gmail.com> wrote: >> 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 >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >