Version 0.2 of the Cache Test plugin

written by admin on octobre 17th, 2006 @ 08:03

As the title implies, I have released a new version of my cache logic test plugin.

Ok, I must admit I have been a bit motivated by that post =P, but anyway, here you are with some new features.

First you are now able to check the actions and fragments caching logic: there are four new methods:

- assert\_cache\_actions - assert\_expire\_actions - assert\_cache\_fragments - assert\_expire\_fragments

They work quite like the corresponding page method, see the documentation for code and examples.

I also changed the way page caching test works. The API is still the same, just the internals have changed. Instead of checking that the page’s cache files are created or removed, I now hijack the ActionController::Base methods so that they records which page are cached or expired. I then use this information in the assertions. No more fiddling with the file system to know if a file is cached or not.

And finally, this release comes with some unit test cases.

The fragment code seems to be working, but I have no application that makes heavy use of fragments so if you find bug in it or have suggestions, don’t hesitate to tell me!

update: I think I have a better idea for the API something along the line of

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def test_caching
  assert_caching do
    get "/my/page"
    assert_page_cached "/my/page"

    get "/my/action"
    assert_action_cached :controller => "my", :action => "action"

    get "/my/fragment"
    assert_fragment_cached :controller => "my", 
                                            :action => "fragment",
                                            :fragment => "foo"
  end
end

I’ve already implemented it, I’ll wait for some feedback before releasing a new version.

Comments

  • Tuxie on 18 oct 03:04

    This is great! Please commit it to a Subversion repository so we can use the standard tools (script/plugin, svn:externals, piston etc) to install and update it...
  • Dam on 18 oct 10:26

    The problem is that I use bazaar-ng...
  • Tuxie on 18 oct 20:44

    hmm.. You could use "tailor":tailor to export it to an external svn repo for read-only use, via cron or a "after-commit" hook. You can get free svn hosting from many places, for example "opensvn.csie.org":csie [tailor]http://progetti.arstecnica.it/tailor/wiki [csie]http://OpenSVN.csie.org
  • Tom Ward on 23 oct 18:08

    I've cleaned up a plugin I've been using that provides similar functionality. Rather than mock out the caching methods, it replaces the caches with temporary versions. It also allows testing outside the context of a request, which is important for me as I have data import processes that need to expire cached output on completion. I'm not sure which approach is best but thought you might be interested to take a look. It's available at: http://svn.popdog.net/plugins/caching_extras/tags/REL-0.1/

Post a comment

Options:

Size

Colors