# A unit test that should pass

**URL:** <https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227>\
**Category:** Rails\
**Created:** [March 26, 2006, 1:44am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227 "2006-03-26T01:44:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [March 26, 2006, 1:44am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227/1 "2006-03-26T01:44:15Z")

</div>

Hi, I wonder why this unit test fails.

The model :  
class Article \< ActiveRecord::Base  
set\_table\_name “publish\_articles”  
belongs\_to :category

validates\_presence\_of :title, :excerpt  
#snip  
end

The test :  
def test\_validate  
@article.title = nil  
@article.excerpt = nil  
assert !@article.save  
assert\_equal 2, !@article.errors.count  
end

!@article.errors.count returns ‘false’ instead of 2  
I tried also with @article.title = ‘’

Any idea ?

---

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [March 26, 2006, 1:53am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227/2 "2006-03-26T01:53:09Z")

</div>

try changing

assert\_equal 2, !@article.errors.count

to be

assert\_equal 2, @article.errors.count

The bang(!) means not and when you place it in front of !@  
article.errors.count it’s returning the opposite of whether there is an  
@  
articles.errors.count value returned, which in this case is false.

---

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [March 26, 2006, 1:54am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227/3 "2006-03-26T01:54:10Z")

</div>

On 3/25/06, Christophe G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Shouldn’t that be?:  
assert\_equal 2, @article.errors.count

---

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [March 26, 2006, 1:54am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227/4 "2006-03-26T01:54:51Z")

</div>

Where is “@article” getting created?

Also, what if you put your validation statements in the model on two  
seperate lines?

---

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [March 26, 2006, 1:58am UTC](https://www.ruby-forum.com/t/a-unit-test-that-should-pass/87227/5 "2006-03-26T01:58:37Z")

</div>

Hooooo yes, I didn’t see the typo !

Should go to bed now, thanks you all !
