我花了最后两个小时搞清楚出了什么问题,但在任何地方找不到答案。
这是我的第一个rails应用程序(除了Hartl的教程)所以解决方案可能很简单..我正在使用Devise来管理我的用户,到目前为止一切都很好。
尝试测试用户模型我定义了这样的工厂:
FactoryGirl.define do
factory :user do
email "g@g.com"
password "123123"
password_confirmation { "123123" }
end
end
,测试是:
describe User do
# pending "add some examples to (or delete) #{__FILE__}"
@user = FactoryGirl.create(:user)
subject(:user)
it { should respond_to(:email) }
it { should respond_to(:password) }
it { should be_valid }
end
但最后一行({应该是__valid})未通过测试。
我已经打印了user / @ user的值(尝试了两者),结果为零。 编辑:这不是零。其
#<User id: 13, email: "email1@factory.com", encrypted_password: "$2a$04$.lWs6yadJu/Ya67xi.W1F.fd6sWLGkzc/59.lgTi0sA7...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-08-27 15:48:23", updated_at: "2012-08-27 15:48:23">
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
validates :email, :presence => true
validates :password, :presence => true
end
我没看到什么?
答案 0 :(得分:4)