is Rails.cache purged between tests?

前端 未结 2 1090
半阙折子戏
半阙折子戏 2020-12-24 00:57

We cache id/path mapping using Rails.cache in a Rails 3.2 app. On some machines it works OK, but on the others values are wrong. The cause is hard to track so I

2条回答
  •  北海茫月
    2020-12-24 01:53

    Add:

    before(:all) do
      Rails.cache.clear
    end
    

    to have the cache cleared before each spec file is run.

    Add:

    before(:each) do
      Rails.cache.clear
    end
    

    to have the cache cleared before each spec.

    You can put this inside spec/spec_helper.rb within the RSpec.configure block to have it applied globally (recommended over scattering it per spec file or case).

    RSpec by default does not clear that cache automatically.

提交回复
热议问题