I just released MockFS 0.1.3. This is a small version, so here’s the changelog:
0.1.3 -- June 11 2006 * Added support for Dir, Dir.glob, Dir.rmdir, File.directory?, File.file?, File.read * File.open supports perms in format like 'w', 'r', and 'a'. * Added RDoc auto-generation to the Gemspec. * override.rb plays better with Rubygems.
A bit on that last point:
mockfs/override.rb alters Kernel.require so that you can require virtual files, side-by-side along with real files. Here’s an example from the RDoc:
require 'mockfs/override' MockFS.file.open( 'virtual.rb', 'w' ) do |f| f.puts "puts 'I am a ruby program living in a virtual file'" end require 'virtual.rb' require 'rexml' # real files are still accessible
I added this because I often encode configuration files as Ruby and then just require them—this is my preferred method, over YAML or XML, since you can have the configuration info be as unstructured as a Hash or an OpenStruct, or if you need something more rigorous you can build a 20-foot-high DSL, all without ever leaving the file. In these cases it’s convenient to be able to swap out these configuration files for tests, which is what you get by plugging
Kernel.require into the MockFileSystem. In the last version, this wasn’t working so well with Rubygems, so I fixed it.
There’s more than one library mucking about with
Kernel.require, in fact: Off the top of my head I can think of MockFS, Rubygems, Rails’ ActiveSupport, and my mutant lib urirequire . It gets crowded in there, but what can I say? It sure is fun to muck around with Ruby’s innards. KernelRequireConf 2007, anyone?