Is there a way to test caching in ur app?

Rails gives use page,action and fragment caching. Is there anyway to write tests to make sure the cache is being expired properly? I'm interested to know what other developers out there feel about this.

For example, I was thinkin maybe I could enable caching in test mode, clear the cache on unittest setup and then after certain actions, load other pages and test the contents (to make sure that stale fragments aren't being used, etc).

You could easily do this with Selenium:

  http://www.openqa.org/

With Selenium you can write a simple DSL to click through the app via one or more browsers with tests in ruby code e.g.

def test_expire_name_div   a=users(:admin)   login_as a   open user_profile_url   wait_for_page_to_load   assert_equal a.name, get_text('name')   a.name = "bob"   a.save! #should expire fragment   refresh_page   assert_equal a.name, get_text('name') end

This is a good way to test across browsers, to test ajax, and can provide easier ways to test some aspects of your app from the browser(s) to the db. Think of it as programmatic acceptance testing (write the DSL with the client even). They're also an impressive client demo (i.e. shiny whilst in operation).

pt.

This might be helpful: http://agilewebdevelopment.com/plugins/page_cache_test