您好我已在applicationname/test/models/product_test.rb
进行这些测试
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
test "product attributes must not be empty" do
product = Product.new
assert product.invalid?
assert product.errors[:title].any?
assert product.errors[:description].any?
assert product.errors[:price].any?
assert product.errors[:image_url].any?
end
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 greater 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
end
但是当我做rake test:models
我收到错误:
SyntaxError: C:/work/applicationname/test/models/product_test.rb:19: syntax error, unexpected '\n' expexting : "="
SyntaxError: C:/work/applicationname/test/models/product_test.rb:24: syntax error, unexpected '\n' expexting : "="
答案 0 :(得分:0)
而不是:
assert_equal["must be greater than or equal to 0.01"],
product.errors[:price]
你应该:
assert_equal ["must be greater than or equal to 0.01"], product.errors[:price]
代码中出现两次,因此请务必修复两个外观。