By default, caching in a Rails application is only enabled in a production environment. To be able to test application logic for caching there are at least two immediate solutions, being (1) enable caching for all tests and (2) enable cache for individual tests. For this article, we shall consider the latter.
Assuming the default caching configuration for test environment
the strategy to enable it for individual tests consists of stubbing Rails.cache and clearing it before each example, like so: