我正在阅读“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发布于 2014-05-23 11:08:18
您有两个块,但只有一个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 classclass是一个块的开始,而test行末尾的do是另一个块。
这种类型的错误总是针对文件的最后一行进行报告,因为它无法判断是否有缺少的end,直到它到达文件的末尾,并且找不到它。
发布于 2014-05-23 11:09:45
您丢失了end for do block.Adding,它应该修复错误。
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 endhttps://stackoverflow.com/questions/23827424
复制相似问题