【发布时间】:2014-05-07 10:46:25
【问题描述】:
我的模型具有如下验证:
# 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
所以我是说这个带有空字段的模型应该通过“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)这个不保存到数据库
标签: ruby-on-rails rspec shoulda