MockFS 0.1.3

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.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'" 
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?

blog comments powered by Disqus
Tagged: ruby

« Previous post

Next post »

Selected referrals to this page

Testing and Debugging Ruby on Rails
First tracked August 29, 2006

… lead developer at odeo has been working on FakeWeb a network mocking toolkit which makes testing of network intensive tasks easy and clean.
Francis Hwuang has released an update to his MockFS mock library to have better support for ruby gems and playing nicely with others.
Bulk Validation
Has Many Josh has been doing bulk sql loading for data import lately. When …