Rails Cache Test Plugin
# Rails Cache Test Plugin The cache test plugin adds assertions to Test::Units::TestCase to check the caching and expiring of pages, actions and fragments in tests
1. Download
The current version is 0.2. For change details, see the changelog.
2. Installation
Unpack into the vendor/plugin and that should be it.
3. Usage
First create an integration test. Then, to test caching of the "/pages/about" and "/pages/contact" pages, add a method like this:
1 2 3 |
def test_caching assert_cache_pages("/pages/about", "/pages/contact") end |
The assert_cache_pages method will
- first make sure that the urls are not cached,
- execute a get on each request,
- assert that the corresponding cache files have been created.
You can also give a block to the assertcachepages method. Instead of executing a get on each url, it will yield the urls. For example:
1 2 3 4 5 6 7 |
def test_caching assert_cache_pages("/pages/about", "/pages/contact") do |url_about, url_contact| post url_about post url_contact end end |
You will also certainly want (and that's really the most interesting part) to check if your cached pages expires when the user is doing some action. For that, here is the assertexpirepages method:
1 2 3 4 5 |
def test_expiring assert_expire_pages("/news/list", "/news/show/1") do |*urls| post "/news/delete/1" end end |
Here the assert_expire_pages method will
- check that the urls are cached,
- execute the post request,
- and assert that the urls are no more cached.
This is great for testing your cache sweepers logic.
There are also method to check action and fragment caching, see the readme file.