2011-06-16 70 views
1

我收到以下錯誤消息:邁克爾·哈特爾指南第6章語法錯誤user_spec.rb

rails_projects/sample_app/spec/models/user_spec.rb:6: syntax error, unexpected ',', expecting ')' 
@attr = (:name => "Example User", :email => "[email protected]") 

後,我的設置,只有設置了user_spec.rb文件 需要「spec_helper」

describe User do 

before(:each) do 
@attr = (:name => "Example User", :email => "[email protected]") 
# pending "add seme examples to (or delete) #{__FILE__}" 
end 

it "should create a new instance given valid attributes" do 
User.create!(@attr) 
end 

it "should require a name" 
end 

我知道我仍然會在代碼中收到待處理消息,但不會出現語法錯誤

回答

4

您需要在此處使用{...}作爲散列語法:

@attr = { :name => "Example User", :email => "[email protected]" } 

Ps。剛剛檢查了教程和it shows the same - 你犯了一個錯字,不用擔心 (在教程中用於代碼的字體本來可以更好!)

+0

@matt,答案是否適合你? – Zabba 2011-06-30 19:00:56

相關問題