# Assert fails with \<false\> is not true

**URL:** <https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016>\
**Category:** Rails\
**Created:** [July 12, 2006, 12:08am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016 "2006-07-12T00:08:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 12, 2006, 12:08am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016/1 "2006-07-12T00:08:04Z")

</div>

Hi,

I have a simple model and written a testcase.

## class Product \< ActiveRecord::Base validates\_presense\_of :name end

class ProductTest \< Test::Unit::TestCase  
fixtures :products

## def test\_invalid product = Product.new assert !product.valid? end end

The testcase fails with a message,  
 is not true.

What is wrong with the testcase? I can see it ruby console that  
“product.valid?” returns false…so “assert !product.valid?” should  
return true…

Any clues what is wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 12, 2006, 3:21am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016/2 "2006-07-12T03:21:41Z")

</div>

The test case is telling you that product.valid? is returning true.  
Have you actually checked the return value?

Cheers,

Pete Y.  
[http://9cays.com/](http://9cays.com/)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 12, 2006, 9:36am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016/3 "2006-07-12T09:36:25Z")

</div>

Hi,

“assert\_valid product” passes…meaning the product.valid? is returning  
“true” in the test case. ☹

But if I check this in ruby console, product.valid? returns “false” and  
I can see all “invalid” errors…but something is weird!

Any ideas what else I should check?

Thanks.

Chris C. wrote:

> Guest wrote:
> 
> > Hi,
> > 
> > I have a simple model and written a testcase.
> > 
> > ## class Product \< ActiveRecord::Base validates\_presense\_of :name end
> > 
> > class ProductTest \< Test::Unit::TestCase  
> > fixtures :products
> > 
> > ## def test\_invalid product = Product.new assert !product.valid? end end
> > 
> > The testcase fails with a message,  
> > is not true.
> 
> Hi,
> 
> I think you need to have it read  
> product = Product.create  
> not  
> product = Product.new
> 
> ## Chris
> 
> ruby -e ‘$_=[1667523425, 1920230770, 539828333, 1634956389, 1914728294,  
> 543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951,  
> 109];$/="";11.times{$/\<\<78.chr};1.times{$/\<\<99.chr};puts$_.pack($/)’

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 12, 2006, 3:31am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016/4 "2006-07-12T03:31:46Z")

</div>

Guest wrote:

> Hi,
> 
> I have a simple model and written a testcase.
> 
> ## class Product \< ActiveRecord::Base validates\_presense\_of :name end
> 
> class ProductTest \< Test::Unit::TestCase  
> fixtures :products
> 
> ## def test\_invalid product = Product.new assert !product.valid? end end
> 
> The testcase fails with a message,  
> is not true.

Hi,

I think you need to have it read  
product = Product.create  
not  
product = Product.new

## Chris

ruby -e ‘$_=[1667523425, 1920230770, 539828333, 1634956389, 1914728294,  
543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951,  
109];$/="";11.times{$/\<\<78.chr};1.times{$/\<\<99.chr};puts$_.pack($/)’

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 12, 2006, 9:54am UTC](https://www.ruby-forum.com/t/assert-fails-with-false-is-not-true/98016/5 "2006-07-12T09:54:44Z")

</div>

Strangely I have this behavior only in the “product” model, the “user”  
model works as expected!
