
require 'book'
class BookTest < Test::Unit::TestCase
def test_book_creation_works
war_and_peace = Book.new("title" => "War and Peace")
war_and_peace.save
mystery_book = Book.find_first "title = 'War and Peace'"
assert war_and_peace.title == mystery_book.title
end
def test_unit_tests_are_independent
mystery_book = Book.find_first "title = 'War and Peace'"
assert mystery_book == nil
end
def test_book_requires_a_title
bitter_ejb = Book.new
assert !bitter_ejb.save
end
end
It is too bad that a tool this useful and simple isn't something recommended to beginners early on. I am picturing programming 101 being test driven from now on. Perhaps it is time to retire "Hello, World!" in favor of an assertion. assertEquals("Hello, World!", atom.greeting()); A new programmer's first task will be a green bar, not a println.