Forum: Ruby on Rails A unit test that should pass

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris C. (Guest)
on 2006-03-26 03:44
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

The test :
def test_validate
    @article.title = nil
    @article.excerpt = nil
    assert !
    assert_equal 2, !@article.errors.count

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

Any idea ?
Tim C. (Guest)
on 2006-03-26 03:53
(Received via mailing list)
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.
Wilson B. (Guest)
on 2006-03-26 03:54
(Received via mailing list)
On 3/25/06, Christophe G. <removed_email_address@domain.invalid> wrote:
Shouldn't that be?:
assert_equal 2, @article.errors.count
Michael G. (Guest)
on 2006-03-26 03:54
(Received via mailing list)
Where is "@article" getting created?

Also, what if you put your validation statements in the model on two
seperate lines?
Chris C. (Guest)
on 2006-03-26 03:58
Hooooo yes, I didn't see the typo !

Should go to bed now, thanks you all !
This topic is locked and can not be replied to.