How Not to Test Validations, Part 1

One of the things I will look at in "Keeping Tests Dry" at next week's erubycon is various ways people test ActiveRecord validations.

Here's one bad idea:

  def test_contact_requires_name
    c =
    err = assert_raise(ActiveRecord::RecordInvalid) {!
    assert_equal "Validation failed: Name can't be blank", 

What's wrong with this example? (More to follow...)

Get In Touch