保护意外的标识符错误

时间:2015-04-24 17:49:13

标签: ruby-on-rails gem guard

我是编码的新手,希望我遵循所有规则来发布这个问题。

我正在阅读Ruby on Rails的介绍,在我的一个例子中,当GUARD运行时,我得到以下'Unexpect tIDENTIFIER'消息,我似乎无法找出原因。

ERROR["test_should_get_about", StaticPagesControllerTest, 0.012288]
test_should_get_about#StaticPagesControllerTest (0.01s)
SyntaxError:         SyntaxError: /Users/NateFeder/_projectbox/rails-tutorial/sample_app/app/controllers/static_pages_controller.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
    About |Ruby on Rails Tutorial Sample App
                  ^
ERROR["test_should_get_home", StaticPagesControllerTest, 0.004128]
test_should_get_home#StaticPagesControllerTest (0.00s)
SyntaxError:         SyntaxError: /Users/NateFeder/_projectbox/rails-tutorial/sample_app/app/controllers/static_pages_controller.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
    About |Ruby on Rails Tutorial Sample App

ERROR["test_should_get_help", StaticPagesControllerTest, 0.008452]
test_should_get_help#StaticPagesControllerTest (0.01s)
SyntaxError:         SyntaxError: /Users/NateFeder/_projectbox/rails-tutorial/sample_app/app/controllers/static_pages_controller.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
    About |Ruby on Rails Tutorial Sample App

我的StaticPagesControllerTest如下:

require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase

test "should get home" do
get :home
assert_response :success
assert_select "title", 'Home | Ruby on Rails Tutorial Sample App'
end

 test "should get help" do
get :help
assert_response :success
assert_select "title", 'Help | Ruby on Rails Tutorial Sample App'

end

test "should get about" do
get :about
assert_response :success
assert_select 'title", "About | Ruby on Rails Tutorial Sample App'

end

end

由于

2 个答案:

答案 0 :(得分:0)

您的错误是您使用不一致的单引号和双引号:

test "should get about" do
get :about
assert_response :success
assert_select 'title", "About | Ruby on Rails Tutorial Sample App'
# ------------^ here

end

这是更主观的,但为了避免这种错误,选择一个(单个或双重)并坚持它可能是一个好主意,除非你必须使用别的东西(即做{{1}字符串插值)

答案 1 :(得分:0)

回过文件夹后,我意识到我有一个额外的layout_file。我删除了额外的文件,错误消失了。活泉!

经验教训。