Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Page Cache Test

Page Cache Test

= Page Cache Test Plugin

This plugin adds two assertions to Test::Units::TestCase to check the caching and expiring of pages in integration tests.

1. Installation

Unpack into the vendor/plugin and that should be it.

2. Usage

First create an integration test. Then, to test caching of the ”/pages/about” and ”/pages/contact” pages, add a method like this:

def test_caching
  assert_cache("/pages/about", "/pages/contact")
end

The assert_cache 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 assert_cache method. Instead of executing a get on each url, it will yield the urls. For example:

def test_caching
  assert_cache("/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 assert_expire method:

def test_expiring
  assert_expire("/news/list", "/news/show/1") do |*urls|
    post "/news/delete/1" 
  end
end

Here the assert_expire 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.

3. License

This plugin is licensed under the MIT license. Complete license text is included in the MIT-LICENSE[link:files/MIT-LICENSE.html] file.

4. Author

This plugin was created by Damien Merenne <dam> and is located at http://blog.cosinux.org/pages/page-cache-test.

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all 2 member details


Membership

+ Join this railsplugin

Record Maintainer

'None'