Topic: Syntax Question Two Errors Returned

Hi

I'm new to testing, and have an assertion which returns two errors. I don't seem to be able to get the formatting for two errors right, just wondering if anyone can provide a hint? Thanks ahead. The test is failing as it expects only one of the errors, but returns the other... and putting them in parentheses hasn't worked for me yet either. I've had a quick look online but couldn't find anything. http://manuals.rubyonrails.com is down at the moment.

  def test_does_a_user_with_no_password_fail
    user = User.new(:email => "test@hotmail.com", :password => "")
    assert !user.valid?
    assert_equal   "email and password must be provided.",
                  "needs to be at least 5 characters long.",
                  user.errors.on(:password)
  end

Re: Syntax Question Two Errors Returned

Try this

   def test_does_a_user_with_no_password_fail
     user = User.new(:email => "test@hotmail.com", :password => "")
     assert !user.valid?
     assert_equal "email and password must be provided.",
                     user.errors.on(:password)[0]
     assert_equal "needs to be at least 5 characters long.",
                     user.errors.on(:password)[1]
   end

errors.on will return an array if there is more than one error, and assert_equal is meant to compare two objects.  If this doesn't work, try switch the [0] and [1].