Skip to content

Instantly share code, notes, and snippets.

@cailinanne
Created November 28, 2011 03:36
Show Gist options
  • Save cailinanne/1398987 to your computer and use it in GitHub Desktop.
Save cailinanne/1398987 to your computer and use it in GitHub Desktop.
Testing cache helpers with Rails 3.1 and Rspec
# spec/support/example_helpers.rb
module ExampleHelpers
module CachingTestHelpers
ActionController::Base.public_class_method :page_cache_path
module ResponseHelper
def action_cached?(request)
request.path.is_action_cached?
end
def page_cached?(request)
request.path.is_page_cached?
end
end
ActionDispatch::TestResponse.send(:include, ResponseHelper)
end
end
class String
def is_action_cached?
Rails.cache.exist?("views/www.example.com#{self}")
end
def is_page_cached?
File.exists? ActionController::Base.page_cache_path(self)
end
end
RSpec.configure do |config|
config.include ExampleHelpers::CachingTestHelpers, :type => :request
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment