assert_respond_to [object], :[method] #does object method exist? ex. assert_respond_to "string", :lowercase
assert_equal [string, [method] #is first string equal to results of second method?
assert_match [regex], [method] #is first regex equal to second string?
assert_nil
assert_not_nil [method] #is method nil?
assert_raise(RuntimeError), [method]
assert_respond_to
assert_no_match
assert_kind_of(Class, object)
def test_whatever_you_want_to_call_your_test do
assert_response_to "string", :lowercase, "This is the error message"
end
class ConditionalTest < Test::Unit::TestCase
def test_one_greater_than_zero
assert 1 > 0, "One is greater than zero"
end
end
Prep the test database before running tests:
rake db:test:prepare
Run db:test:prepare and all tests:
rake test
Testing if the model is valid without a particular field:
class ModelTest < ActiveSupport::TestCase
test "model is invalid without a status" do
model = Model.new
assert !model.valid?, "Without a status, the model is not valid"
end
end
Testing for status length:
should ensure_length_of(:status).is_at_least(3).is_at_most(140)
Testing for numeral and uniqueness:
should validate_numericality_of(:id)
should validate_uniqueness_of(:id)