Topic: Test if error_message are displayed

Hey Forum
I have this test-method,  but I cant get the assert_tag to work.

def test_failing_create
    product =
    assert_equal false,
    assert_equal 1, product.errors.size
    assert product.errors.on(:name)
    assert_tag :div, :attributes => { :id => "errorExplanation" }

But then I get this error in test.
test/functional/products_controller_test.rb:32:in `test_failing_create']:
expected tag, but no tag found matching {:attributes=>{:id=>"errorExplanation"}, :tag=>"div"} in:
<nil> is not true.

But here it seems like no html-code are returned. Its works when I see it in a browser.

What are am doing wrong?

Re: Test if error_message are displayed

I have found the problem by my self.
Its because I use restfull implementation, so I have to use post :product in my testmethod.
Like this.

  def test_should_not_create_product
    old_count = Product.count
    post :create, :product => { :name => "" }
    assert_equal old_count, Product.count
    assert_tag :div, :attributes => { :id => "errorExplanation" }