A unit test that should pass

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 ?

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.

On 3/25/06, Christophe G. [email protected] wrote:

Shouldn’t that be?:
assert_equal 2, @article.errors.count

Where is “@article” getting created?

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

Hooooo yes, I didn’t see the typo !

Should go to bed now, thanks you all !