根据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改为“”,blankspace,这与测试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
答案 0 :(得分:0)
偶"".nil?
返回false。如果您需要测试空白,只需使用ActveSupport提供的方法blank?
。