I'm going to use Dalli cache as key-value store.
Usually in production and development environments we have line
config.cache_store = :dalli_store
so then we can use Rails.cache
construction to read from and write to cache.
But in the test environment usually, we don't have this config line.
What is the right way to set up a cache in a test environment in purpose to test my storing logic?
P.S. I'm using Linux(Ubuntu)
dalli is a client for the caching service (memcached) set it globally whatever the environment, ie in your config/application.rb
config.cache_store = :dalli_store
caching being deactivated in the test environment is a common approach, check config/environments/test.rb
config.action_controller.perform_caching = false
so you can enable it for the test environment, but it could lead to some weird conflicts best is probably to enable it on the go for a specific specs only:
before do # enable caching
@caching_state = ActionController::Base.perform_caching
ActionController::Base.perform_caching = true
end
after do # disable caching
ActionController::Base.perform_caching = @caching_state
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With