Q:

Should I write rails tests with the def or test keyword?

This seems like a simple question but I can't find the answer anywhere.  I've noticed that in general, tests in a Ruby on Rails app can be written as:
  test "the truth" do
    assert true
  end

or
  def the_truth
    assert true
  end

It seems newer material writes tests the first way, but I can't seem to find a reason for this.  Is one favored over the other?  Is one more correct? Thanks.

A:

There has been a shift in recent years from short, abbreviated test names to longer, sentence-like test names. This is partly due to the popularity of RSpec and the concept that tests are specs and should be descriptive.
If you prefer descriptive test names, I highly recommend going with the test method. I find it to be more readable.
test "should not be able to login with invalid password" do
  #...
end

def_should_not_be_able_to_login_with_invalid_password
  #...
end

Also, because the description is a string it can contain any characters. With def you are limited in which characters you can use.

