【发布时间】:2013-02-12 21:36:51
【问题描述】:
世界上到底发生了什么??我的测试没有通过,我在整个教程中都非常小心(这次)。请告诉我为什么会弹出remember_token错误。
这是我的错误: 失败:
1) User
Failure/Error: it { should respond_to(:remember_token) }
expected #<User id: nil, name: "Example User", email: "user@example.com", created_at: nil, updated_at: nil, password_digest: "$2a$04$HUTzfhPB9eOgNaBIwQZn/.BpGt4h/v9wgLlo.UoMoh8Q..."> to respond to :remember_token
# ./spec/models/user_spec.rb:28:in `block (2 levels) in <top (required)>'
Finished in 0.19682 seconds
22 examples, 1 failure
Failed examples:
rspec ./spec/models/user_spec.rb:28 # User
这是我的代码:
db/migrate/[时间戳]_add_remember_token_to_users.rb
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end
spec/models/user_spec.rb 需要'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:remember_token) }
it { should respond_to(:authenticate) }
it { should be_valid }
it { should respond_to(:authenticate) }
.
.
.
【问题讨论】:
-
你记得运行
rake db:migrate吗? -
是的,我做到了,我做了所有事情......显然没有......
-
我不确定你的意思......你仍然收到错误吗?
标签: ruby-on-rails-3.2 railstutorial.org