Last Updated: February 25, 2016
·
1.069K
· rossta

Toggle Rails Caching in RSpec Suites

In spec_helper or another support file required by your spec:

RSpec.configure do |config|
  config.around(:each, :caching) do |example|
    caching = ActionController::Base.perform_caching
    ActionController::Base.perform_caching = example.metadata[:caching]
    example.run
    ActionController::Base.perform_caching = caching
  end
end

In your spec:

ruby describe "visit the homepage", :caching => true do # test cached stuff end