[英]Rake Aborted! Syntax Error:
我正在學習《用Rails 4進行敏捷Web開發》一書,我是一個完整的初學者,不了解一些問題。
我剛試過rake test:models
命令
我得到了回報:
rake aborted!
SyntaxError: /Users/********/Desktop/depot/test/models/product_test.rb:11: syntax error, unexpected end-of-input, expecting keyword_end
這到底是什么意思? 我一直在逐字逐句地閱讀本書,並且遇到了這個問題。
在此先感謝您提供有用的答案和想法!
這是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
您有2個塊,但只有一個end語句; end
需要有另一個目的:
require 'test_helper'
class ProductTest < ActiveSupport::TestCase # <== this is the start of the class
test "product attributes must not be empty" do # <== this is the start of a block
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 # <== this is missing
end # <== this is the end of the class
class
是一個塊的開始,而test
行末尾的do
是另一個。
此類錯誤始終會針對文件的最后一行進行報告,因為直到到達文件末尾並且找不到它時,它才能告訴您缺少end
。
您缺少do
塊的end
,添加它應該可以修復錯誤。
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 #do end
end #class end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.