使用rails 4我在我的用户模型中使用has_secure_password,技巧说如果我没有设置:password_confirmation它将永远不会被触发,但为什么当我运行测试时我得到错误:密码确认不能为空如下:
Failures:
1) User
Failure/Error: it { should be_valid }
expected #<User id: nil, name: "joe", email: "joe@mail.com", created_at: nil,
updated_at: nil, password_digest: "$2a$04$mcRr/msgYQR3kBVc3kv/m.UotBJuJuSXZKMw
/eHTvU87..."> to be valid, but got errors: Password confirmation can't be blank
Run Code Online (Sandbox Code Playgroud)
我的测试文件看起来像:
require 'spec_helper'
describe User do
before { @user = User.new(name: 'joe', email: 'joe@mail.com', password: 'foo') }
subject { @user }
#....
#....
describe "when password is not present" do
before { @user.password = "" }
it { should_not …Run Code Online (Sandbox Code Playgroud)