Rspec tests of rack_cache

113 Views Asked by At

I am using rack_cache to cache some of the responses withing Redis. I would like to test with rspec so I would be sure that caching works. I can do this with:

config.action_dispatch.rack_cache = true

The problem is because I would like to set this setting on single test, not for whole app.

For high level caching we can use around bock:

config.around(:each, :caching) do |example|
  caching = ActionController::Base.perform_caching
  ActionController::Base.perform_caching = example.metadata[:caching]
  example.run
  ActionController::Base.perform_caching = caching
end

Is there a way to do something similar for Rack cache?

1

There are 1 best solutions below

0
On BEST ANSWER

I ended up deliting redis cache before running tests:

redis_keys = $redis.keys('*')
$redis.del(redis_keys) if redis_keys.count > 0