Is there a way to simulate the functional test being called on
different days? In other words, the functional test may yield a
different result when run on different dates. I’d like to set the
system date in the test to see how the controller responds on different
dates.
Is there a way to simulate the functional test being called on
different days? In other words, the functional test may yield a
different result when run on different dates. I’d like to set the
system date in the test to see how the controller responds on different
dates.
Thanks!
Tom
You could get the system date from an object, and then use Mocks to
control what the object sends out.
Don’t forget also adding to your /test/fixtures/model.yml files lines
like
<% 3.seconds.ago.to_s :db %>. Then your production code can rely on the
current time without passing it in. Your test fixture data will always
have
the correct values relative to the time of the test run.
You can use a mocking/stubbing library to stub out Time.now in your
test setup.
Now that I think about it, this approach really is not good. Most
time-sensitive logic should be in your models. In all the methods you
write which use Time.now, you should pass it in to the method like
this: