这是出生日期的验证,我需要使用 rspec 对其进行测试。
验证 :date_of_birth, date: { before: Proc.new { Date.today }, message: 'must be before today' }, on: :create
这是我做的,但似乎不对
it "should allow valid birth date" do
date_of_birth = Time.now
allow(Time).to receive(:now).and_return(date_of_birth)
date_of_birth.capture_item("date of birth")
expect(date_of_birth.items[0].date_captured).to eq(date_of_birth)
end
it 'should allow valid birth date' do
person = Person.new(date_of_birth: Date.yesterday)
person.valid?
expect(person.errors[:date_of_birth]).to include('must be before today')
end
我是一名优秀的程序员,十分优秀!