ruby on rails - Spec is failing on the same hour -
in app have few specs depend on distracting dates:
survey_instance.created_at + 1.day
then check if collection of survey_instances have proper size. specs fails @ 3 a.m. how can distract dates avoid problem?
for problem, timecop invented!
a gem providing "time travel" , "time freezing" capabilities, making dead simple test time-dependent code. provides unified method mock time.now, date.today, , datetime.now in single call.
bundle , change spec like:
timecop.freeze(2015, 10, 21, 10, 5, 0) # whatever assertion end
this make sure test run @ same time of day.
Comments
Post a Comment