A unit test that should pass


#1

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 ?


#2

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.


#3

On 3/25/06, Christophe G. removed_email_address@domain.invalid wrote:

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


#4

Where is “@article” getting created?

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


#5

Hooooo yes, I didn’t see the typo !

Should go to bed now, thanks you all !