I’m building an app in which quite a bit of data is dependant on dates
(and times), and I have logic that depends on when ‘today’ is. I’m
trying to get some better functional tests written, and am unsure of
the best way to approach it.
The problem is that I want the tests to run against the same data
every time, whether I run it on Tuesday or Thursday or whatever day.
My fixtures are dynamic in that they add data relative to the
beginning of ‘this week’ (day of the week is important for this data
to make sense, so I can’t go relative to Date.today directly). In one
of my actions, I return data for the ‘next three days’, and as such,
tests are run against different data depending on what day of the week
the tests are run on. This is not what I want - tests should get run
against the same data each time (imho).
I know this problem has to have been solved in the past, but I just
can’t seem to put my finger on a clean method to run these tests on a
consistent set of data. Do people mock out the Date.today method to
return a specific date, or what?
Thanks for any hints,
firstname.lastname@example.org or email@example.com