Michael Hartl指导第6章语法错误user_spec.rb

时间:2011-06-16 02:11:41

标签: ruby-on-rails

我收到以下错误消息:

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

设置完成后,只设置user_spec.rb文件     需要'spec_helper'

describe User do

before(:each) do
@attr = ( :name => "Example User", :email => "user@example.com")
#  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

我知道我仍然会在代码中收到待处理的消息但不是语法错误

1 个答案:

答案 0 :(得分:4)

您需要在此处使用{...}哈希语法:

@attr = { :name => "Example User", :email => "user@example.com" }

聚苯乙烯。刚刚查看了教程和it shows the same - 你输错了,不用担心 (本教程中用于代码的字体本来可以更好!)