Date and time logic has a well-deserved reputation as some of the most complex and irritating logic in any application. Testing calendar logic, including time-based reports, automatic logouts, and “1 day ago” text displays, can be a particular headache. Still, we can do a couple of things to simplify the time-logic beast.

Part of the problem

We have a test that uses factories. We’d like to test some time-based code that might be used in a search or report result. This goes in spec/unit/project_spec.rb:

Get hands-on with 1400+ tech skills courses.