read_page_cache¶ ↑
Synopsis¶ ↑
The purpose of the module is to cache web pages used for testing by overriding the classes’ read_page method and replacing it with one that will cache pages.
Usage¶ ↑
Your main code needs to have a read_page(page) instance method(s). Here’s an example:
class ClassName def read_page(page) open(page).read end end
Then your test code should include:
# default directory is '/tmp' directory = '/path/to/cache/files' require 'cache_extensions' ReadPageCache.attach_to ClassName, directory
You may attach_to however many classes that you need to.
If you want to override all the read_page(page) methods in your application, then your test code can instead use:
# default directory is '/tmp' directory = '/path/to/cache/files' require 'cache_extensions' ReadPageCache.attach_to_classes directory
That’s it. The first time you run your tests, the web pages your application accesses with read_page will be cached, then the cached files will be used by all subsequent accesses. You may want to review the cache and add any files you want to your version control system.
Copyright¶ ↑
Copyright © 2009 Roy Wright. See LICENSE for details.