Forum: Ruby on Rails These objects aren't equal..I'm confused

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.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-03-21 04:45
(Received via mailing list)
I'm testing to see if two objects are equal.  One is accessed directly
from the fixture, and the other is accessed through a relationship.
Here's the test:

def test_hero
    assert_equal players(:hero), hands(:first).hero
end

Anyway, the values are exactly the same as far as I can tell.  The
only difference is the object id, but Ruby compares the values, right?
 This just stopped working when I added another db field to the Hand
class, but that shouldn't affect this I'd think..any ideas?


  1) Failure:
test_hero(HandTest) [test/unit/hand_test.rb:34]:
<#<Player:0x2208b24
 @attributes=
  {"card1"=>"Kh",
   "card2"=>"Qd",
   "hero"=>true,
   "hand_id"=>1,
   "seat"=>3,
   "id"=>3,
   "range"=>nil,
   "chips"=>2500}>> expected but was
<#<Player:0x2207d14
 @attributes=
  {"card1"=>"Kh",
   "card2"=>"Qd",
   "hero"=>true,
   "hand_id"=>1,
   "seat"=>3,
   "id"=>3,
   "range"=>nil,
   "chips"=>2500}>>.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-03-21 07:16
(Received via mailing list)
Just test the object.id, which will tell you what you want to know.

I just checked AWDR, and it appears they always use attributes with
assert equal.

--
-- Tom Mornini
119af50160cabfe1fb6f2f05f5018c64?d=identicon&s=25 James Ludlow (Guest)
on 2006-03-21 07:29
(Received via mailing list)
On 3/21/06, Tom Mornini <tmornini@infomania.com> wrote:
> Just test the object.id, which will tell you what you want to know.

Are you sure that's appropriate for a test case?  I personally want
more checking than that.

-- James
This topic is locked and can not be replied to.