# These objects aren't equal..I'm confused

**URL:** <https://www.ruby-forum.com/t/these-objects-arent-equal-im-confused/55449>\
**Category:** Rails\
**Created:** [March 21, 2006, 4:45am UTC](https://www.ruby-forum.com/t/these-objects-arent-equal-im-confused/55449 "2006-03-21T04:45:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 21, 2006, 4:45am UTC](https://www.ruby-forum.com/t/these-objects-arent-equal-im-confused/55449/1 "2006-03-21T04:45:59Z")

</div>

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}\>\>.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 21, 2006, 7:29am UTC](https://www.ruby-forum.com/t/these-objects-arent-equal-im-confused/55449/2 "2006-03-21T07:29:39Z")

</div>

On 3/21/06, Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 21, 2006, 7:16am UTC](https://www.ruby-forum.com/t/these-objects-arent-equal-im-confused/55449/3 "2006-03-21T07:16:17Z")

</div>

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 M.
