Writing a Unit Test in Rails
Good, we can run tests with a single rake task. On to writing a test so we can implement something in our application. So, we want to validate the presence of the body. We'll write a simple test for that in the post_test.rb file. The test simply tries to create a Post object and save it without assigning a title. The assert assertion will fail if its first argument is false or nil. Since we want the opposite of this (to fail if it's true, or if it was saved successfully without a title), we'll simply use the ! operator.
class PostTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
test "must have a body" do
p = Post.new
assert !p.save, "Post was saved without a body"