2016-12-18 8 views
-1

は私が取得していますエラーメッセージです予想:Railsのテストエラー---ここ+++実際

Failure: 
ProductTest#test_product_price_must_be_positive [/home/jatin/work/depot/test/models/product_test.rb:18]: 
--- expected 
+++ actual 
@@ -1 +1 @@ 
-["must be geater than or equal to 0.01"] 
+["must be greater than or equal to 0.01"] 

これは、テストコードです:

test "product price must be positive" do 
product = Product.new(title: "My Book Title", description: "yyy", image_url: "zzz.jpg") 
product.price = -1 
assert product.invalid? 
assert_equal ["must be geater than or equal to 0.01"], 
    product.errors[:price] 

product.price = 0 
assert product.invalid? 
assert_equal ["must be greater than or equal to 0.01"], 
    product.errors[:price] 

product.price = 1 
assert product.valid? 
end 

これは内部のコードですapp/models/product.rbファイル:

class Product < ApplicationRecord 
validates :title, :description, :image_url, presence: true 
validates :price, numericality: {greater_than_or_equal_to: 0.01} 
validates :title, uniqueness: true 
validates :image_url, allow_blank: true, format: { 
    with: %r{\.(gif|jpg|png)\Z}i, 
    message: 'must be a URL for GIF, JPG or PNG image.' 
} 
end 

解決方法を提案してください。あなたがタイプミスしてい

+0

あなたは、テストの失敗を見ていましたか? 2つの弦を比較しましたか? –

答えて

1

assert_equal ["must be geater than or equal to 0.01"], 
#      ^here 
# Change to : 
assert_equal ["must be greater than or equal to 0.01"], 
関連する問題