首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Michael Hartl指南第6章语法错误user_spec.rb

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

Stack Overflow用户
提问于 2011-06-16 10:11:41
回答 1查看 264关注 0票数 1

我收到以下错误消息:

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

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

我知道我仍然会在代码中得到一条挂起的消息,但是不会出现语法错误

EN

回答 1

Stack Overflow用户

发布于 2011-06-16 10:17:20

您需要在此处使用{...} for Hash语法:

代码语言:javascript
复制
@attr = { :name => "Example User", :email => "user@example.com" }

Ps。只需检查教程和it shows the same -你犯了一个拼写错误,不用担心(教程中的代码使用的字体应该更好!)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6366423

复制
相关文章

相似问题

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