我尝试指定我的模型的验证这是我的模型
class Account < CouchRest::Model::Base
property :user, String
property :password, String
property :name, String
property :email, String
property :activate, TrueClass, :default => true
validates_presence_of :user, :password, :name, :email
validates_length_of :password, :in => 6..15, :if => lambda{|account| !account.password.blank? }
validates_uniqueness_of :user, :if => (lambda{|account| !account.user.blank?})
end在我的model_spec中,我正在尝试这样做
account = Account.new
account.should have(1).error_on_presence_of(:email)但是我得到了6个错误而不是1个错误
我认为这可能是由沙发垫的验证造成的,但不确定。
有人能帮我澄清一下吗?
附注:如果我在控制台中验证相同的模型,我会得到4个对应于4个空属性的错误
发布于 2011-02-18 13:41:43
看起来你期望的是1个错误,但实际上有6个。要找出错误散列中的内容,你可以设置一个临时期望:
`account.errors.should == {}然后,示例将失败,RSpec将打印错误散列的值,您可以看到实际生成了哪些错误。
https://stackoverflow.com/questions/5024415
复制相似问题