我正在寻找简洁的代码来测试Rails Unittests中的验证。测试的简单语法验证错误
目前,我做这样的事情
test "create thing without name" do
assert_raise ActiveRecord::RecordInvalid do
Thing.create! :param1 => "Something", :param2 => 123
end
end
我想有一个更好的方式,也显示了验证消息?
解决方案:
我不需要额外的框架目前的解决方案是:
test "create thing without name" do
thing = Thing.new :param1 => "Something", :param2 => 123
assert thing.invalid?
assert thing.errors.on(:name).any?
end
谢谢s的答复。我会尝试rspec和其他一些时间。现在我用assert(record.invalid?)和assert_equal([],record.errors.full_messages)帮助自己 – Roman 2009-09-29 09:07:31