首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拉克流产了!语法错误:

问拉克流产了!语法错误:
EN

Stack Overflow用户
提问于 2014-05-23 10:59:24
回答 2查看 1.3K关注 0票数 1

我正在阅读“Rails 4的敏捷Web开发”一书,我是一个完全的初学者,不了解一些问题。

我刚刚尝试了rake test:models命令

我得到了回报:

代码语言:javascript
复制
rake aborted!
SyntaxError: /Users/********/Desktop/depot/test/models/product_test.rb:11: syntax error, unexpected end-of-input, expecting keyword_end

这到底是什么意思?我逐字逐句地看了这本书,并遇到了这个问题。

提前感谢您的帮助和想法!

这是product_test.rb代码

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-23 11:08:18

您有两个块,但只有一个end语句;最后需要有另一个end:

代码语言:javascript
复制
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,直到它到达文件的末尾,并且找不到它。

票数 1
EN

Stack Overflow用户

发布于 2014-05-23 11:09:45

您丢失了end for do block.Adding,它应该修复错误。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23827424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档