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
ありがとう返信用に私はrspecと他の人にしばらくお試しになります。今のところ私はassert(record.invalid?)とassert_equal([]、record.errors.full_messages)を使って自分自身を手助けします。 – Roman