0
我的模型验证,如:为什么我的RSpec的测试通过时,我的模型验证失败,因为它应该
# Account Model
validates :email, presence: true
validates :password, presence: true
所以我创建了一个factory_girl这个模型有一个像空值:
factory :account do
end
trait :empty do
email ""
password ""
end
所以我的测试看起来像:
it "doesn't allow empty fields" do
account = create(:account, :empty)
account.should_not be_valid
end
所以我说,这个模型中,与空字段,应该失败validat与“should_not”离子。
然而,当我运行RSpec的我得到这个错误:
Validation failed: Email can't be blank, Password can't be blank
# ./spec/models/account_spec.rb:29:in `block (3 levels) in <top (required)>'
什么是我的测试问题?
尝试'account = build(:account,:empty)'这个不保存到db –