Rails/RSpec toggle cache for a single test

本小妞迷上赌 提交于 2019-12-04 05:02:17

in spec_helper.rb

RSpec.configure do |config|
  config.before(:example, disable_cache: true) do
    allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::NullStore.new)
  end

  config.after(:example, disable_cache: true) do
    allow(Rails).to receive(:cache).and_call_original
  end
end

in xxx_spec.rb

RSpec.describe "a group without matching metadata" do
  it "does not run the hook" do
     puts Rails.cache.class
  end

  it "runs the hook for a single example with matching metadata", disable_cache: true do
     puts Rails.cache.class
  end
end

https://www.relishapp.com/rspec/rspec-core/docs/hooks/filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!