Testing
Last updated
Was this helpful?
Last updated
Was this helpful?
TODO: Write about why rspec over minitest
There's a great gem called but since a few versions ago Rails has its own implementation that is slightly more lightweight but also covers most common use cases.
The module in question is ActiveSupport::Testing::TimeHelpers
and to use it you should first include it in your rails_helper.rb
file:
You can then easily use freeze_time
, travel
and travel_to
methods, which comes in very handy when dealing with integration and unit tests that are time related. For bonus points you can wrap it up in a block to never worry about having to restore previous state again.
Here are a few examples: