Skip to content

Instantly share code, notes, and snippets.

@nruth
Created September 4, 2011 18:37
Show Gist options
  • Save nruth/1193290 to your computer and use it in GitHub Desktop.
Save nruth/1193290 to your computer and use it in GitHub Desktop.
a few cucumber/rspec test steps for rails static page caching
Then /^a static page cache file for #{capture_model} should not exist$/ do |pickle_ref|
page = model!(pickle_ref)
page_cache_exist?(page).should be_false
end
Then /^a static page cache file for #{capture_model} should exist$/ do |pickle_ref|
page = model!(pickle_ref)
page_cache_exist?(page).should be_true
end
Then /^the static cache file for #{capture_model} should include: "([^"]*)"$/ do |pickle_ref, expected_string|
page = model!(pickle_ref)
page_cache_file_contents(page).should =~ /#{Regexp.escape expected_string}/
end
module PageCacheStepHelpers
def cached_file_path_for_page(page)
path = ActionController::Base.page_cache_directory + page.path + '.html'
end
def page_cache_exist?(page)
File.exist? cached_file_path_for_page page
end
def page_cache_file_contents(page)
File.read cached_file_path_for_page(page)
end
end
World(PageCacheStepHelpers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment