# (strange) error on assert\_equal

**URL:** <https://www.ruby-forum.com/t/strange-error-on-assert-equal/148800>\
**Category:** Rails\
**Created:** [September 17, 2008, 7:57am UTC](https://www.ruby-forum.com/t/strange-error-on-assert-equal/148800 "2008-09-17T07:57:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [September 17, 2008, 7:57am UTC](https://www.ruby-forum.com/t/strange-error-on-assert-equal/148800/1 "2008-09-17T07:57:09Z")

</div>

Hi all,

I’m having error on all unit test. Even this one:

hash = { :title =\> “recipe title”,  
:description =\> “recipe description”,  
:serving =\> 1,  
:directions =\> “do it”  
}  
recipe\_expected = Recipe.new(hash)  
recipe\_should\_be\_equal = Recipe.new(hash)  
assert\_equal(recipe\_expected, recipe\_should\_be\_equal)

And this is the error i get:

test\_should\_be\_equal  
FAIL  
./test/unit/recipe\_test.rb:16:in `test\_should\_be\_equal’  
\<#\<Recipe id: nil, title: “recipe title”, serving: 1,  
description:  
“recipe description”, directions: “do it”, created\_at: nil, updated\_at:  
nil\>\> expected but was  
\<#\<Recipe id: nil, title: “recipe title”, serving: 1,  
description:  
“recipe description”, directions: “do it”, created\_at: nil, updated\_at:  
nil\>\>.

As far as i can see, the object is the same. I’m wondering why this is  
happening.

Thanks,

Dida

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [September 17, 2008, 9:01am UTC](https://www.ruby-forum.com/t/strange-error-on-assert-equal/148800/2 "2008-09-17T09:01:02Z")

</div>

On Sep 17, 6:56 am, “Adinda P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,

> As far as i can see, the object is the same. I’m wondering why this is  
> happening.

That’s just how == is implemented for activerecord: if they have the  
same id then they are equal, if not (or if one is unsaved) then they  
are not equal (since saving them would result in 2 different rows in  
the database.

Fred
