2014-09-22 17 views
0

你好,我有更新我的測試文件下applicationname/test/models/product_test.rb的Ruby on耙測試:機型語法錯誤

與這些測試

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

相反的:

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] 

它在代碼中出現兩次,所以一定要解決這兩個出場。