根据 Hardl 在 Ruby on rails 中,您可以根据以下内容编写密码确认,但是我无法使用该系列中的最后一个测试:
#IS THIS A VALID TEST?
describe "when password confirmation is not present" do
before { @user.Password_confirmation = nil }
it { should_not be_valid }
end
所以我的问题是这样做是否有效,我将最后一部分中的 nil 更改为“”,空格,这与针对 nil 进行测试时是否相同?:
describe User do
before { @user = User.new(Address:"Dummy Address",Email: "user@example.com", FirstName:"Jim", LastName:"Beam", Password:"ABC123", Password_confirmation:"ABC123", Phone:"+46000", Username:"ExampleUser", Zip:"22646" ) }
subject { @user }
puts "TEST"
it { should respond_to(:FirstName) }
it { should respond_to(:LastName) }
it { should respond_to(:Email) }
it { should respond_to(:password_digest) }
it { should respond_to(:Password) }
it { should respond_to(:Password_confirmation) }
it { should be_valid }
describe "when password is not present" do
before { @user.Password = @user.Password_confirmation = " " }
it { should_not be_valid }
end
describe "when password doesn't match confirmation" do
before { @user.Password_confirmation = "mismatch" }
it { should_not be_valid }
end
#IS THIS A VALID TEST?
describe "when password confirmation is not present" do
before { @user.Password_confirmation = " " }
it { should_not be_valid }
end