मैं ऐसा दिखता है जैसे मेरी Waiver
मॉडल पर एक age
विधि है:तुलना में विफल रहा है
def age(date = nil)
if date.nil?
date = Date.today
end
age = 0
unless date_of_birth.nil?
age = date.year - date_of_birth.year
age -= 1 if date < date_of_birth + age.years #for days before birthday
end
return age
end
मैं तो एक कल्पना है कि लग रहा है जैसे:
it "calculates the proper age" do
waiver = FactoryGirl.create(:waiver, date_of_birth: 12.years.ago)
waiver.age.should == 12
end
जब मैं इस spec को चलाने के लिए मुझे comparison of Date with ActiveSupport::TimeWithZone failed
मिलता है। मैं क्या गलत कर रहा हूं?
Failures:
1) Waiver calculates the proper age
Failure/Error: waiver.age.should == 12
ArgumentError:
comparison of Date with ActiveSupport::TimeWithZone failed
# ./app/models/waiver.rb:132:in `<'
# ./app/models/waiver.rb:132:in `age'
# ./spec/models/waiver_spec.rb:23:in `block (2 levels) in <top (required)>'
मैं नहीं जानता कि क्यों यह विफल हो रहा है, लेकिन यह ठीक काम कर रहा है, तो आप '12.years.ago को date_of_birth सेट करें: अपने तुलनात्मक समय-टू-डेट करने के लिए, अभिव्यक्ति के बजाय के रूप में लिखा जा सकता है। to_date' और '12.years.ago' नहीं। गहराई से स्पष्टीकरण के लिए – oldergod