Created
November 28, 2011 03:36
-
-
Save cailinanne/1398987 to your computer and use it in GitHub Desktop.
Testing cache helpers with Rails 3.1 and Rspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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