2015-04-24 45 views
1

我是新來編碼,並希望我遵循所有的規則相應發佈此問題。保護意外的tIdentifier錯誤

我正在經歷一個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 

感謝

回答

0

你的錯誤是,你使用的不一致單VS雙引號:

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

end 

這是比較主觀的,但爲了避免這種錯誤,選擇一個(單或雙)和stic可能是一個好主意k去它,除非你必須使用別的東西(即做#{}字符串插值)

+0

謝謝閃光。我在發佈問題並修復問題後看到了這一點。儘管如此,我仍然繼續得到錯誤。 – Nate

0

回去後,我意識到我有一個額外的layout_file。我刪除了額外的文件,錯誤消失了。活泉!

經驗教訓。

相關問題