我尝试在我的rspec场景中使用Rails.cache.read和Rails.cache.write助手,但它不起作用。我正在使用dalli_store进行缓存存储。我写了
ActionController::Base.perform_caching = true 在任何随机测试场景中,然后只运行此rspec。当我跳到断点的下一行并尝试在控制台中编写
Rails.cache.write("f", "b") => true
Rails.cache.read("f") => nil 当我在dev环境中运行的控制台中做同样的事情时,我已经得到了所有预期的结果。它将值存储在缓存中并将其返回
发布于 2015-10-21 06:28:17
是否配置了Dalli
config.cache_store = :dalli_store在您的config/ environment /test.rb环境中?我相信它默认为:null_store,这意味着您的测试环境将不会启用缓存。此外,请确保在等级库运行后将ActionController::Base.perform_caching恢复到其原始状态。
https://stackoverflow.com/questions/33247600
复制相似问题