【发布时间】:2016-07-14 09:32:21
【问题描述】:
我验证一个日期字段如下:
验证:return_date,包含:{in:(Date.today+1.day..Date.today+4.weeks)}
我使用 Rspec 语法对其进行测试,如下所示:
it "should only accept return date that is later than the current date" do
quotation_request = FactoryGirl.build(:quotation_request, return_date: Date.today)
expect(quotation_request.valid?).to be_falsy
end
报价请求模型中的验证:
validates :return_date, inclusion: {in:(Date.today+1.day..Date.today+4.weeks)
这行得通。我想知道是否有一种方法可以使用 Shoulda 匹配器来测试它,如果可以,使用哪一个以及如何测试?
【问题讨论】:
标签: rspec-rails ruby-on-rails-4.2 shoulda