在运行涉及ActionView::Template::Error: RSpec::Mocks::Double#marshal_dump returned same class instance
的测试时得到Rails.cache.fetch
。在我的config / environments / test.rb我禁用缓存(我认为):
config.cache_store = :null_store
config.action_controller.perform_caching = false
我的缓存方法采用proc并执行此操作
def use_cached(evaluate_value_proc, key, cache_options)
Rails.cache.fetch(key, cache_options) do
evaluate_value_proc.call
end
end
在测试中,我希望缓存丢失,而只是再次调用该块。这是怎么回事?
谢谢
我通过模拟exist?
的memory_store
方法返回false
,以便fetch
方法将调用block
的方式测试了这些情况
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache.lookup_store(:memory_store))
allow_any_instance_of(ActiveSupport::Cache::MemoryStore).to receive(:exist?).and_return(false)