0
に渡し:Railsのテストはフィクスチャで失敗が、私がテストを持っている直接オブジェクト作成
test 'gift should not be saved with a non-numeric price' do
@gift = gifts(:gift_without_numeric_price)
assert_not @gift.save, 'gift was saved with non-numeric name'
end
それは、この治具を使用しています。
validates :estimated_price,
presence: true,
numericality: true
:
gift_without_numeric_price:
name: "pinecones"
description: "these pinecones smell really good"
estimated_price: "object"
link: "www.google.com"
私Gift
モデルは、このようになります
「オブジェクト」は数値ではないので、テストが成功すると予想していたので、@gift.save
をfalseに戻し、assert_not
が最終的にtrueを返すようにします。しかし、何らかの理由でテストが失敗します。私はギフトのオブジェクトを作成するための直接的な方法を使用すると、テストはこのようになりますし、テストに合格:
test 'gift should not be saved with a non-numeric price' do
@gift = Gift.new(name: 'aa', description: 'description', link: 'www.google.com', estimated_price: 'object')
assert_not @gift.save, 'gift was saved with non-numeric name'
end
私は、フィクスチャと間違って何をしているのですか?
私はあなたの条件とパスをチェックし、あなたのカスタム検証を書くことができthough..itフロート – Mark
あるべき価格は整数になりたくありません検証する。 –