Greetings!
Next down my non-stop pipeline of absolutely necessary libraries that only I seem to need: FileSystem, a library that will mock out File, FileUtils, Dir, and other file-dependent built-in classes. It aims to simulate an entire file-system in memory for the purposes of testing.
http://rubyforge.org/projects/filesystem/
== HOW DOES IT WORK? ==
To use it in live code, you call get methods on the FileSystem module:
FileSystem.get_dir => Dir
FileSystem.get_file => File
FileSystem.get_file_utils => FileUtils
FileSystem.get_dir.entries( '.' ) => [ '.', '..', 'file1', ... ]
(I'm thinking about adding a voodoo.rb file that actually re-assigns the constants Dir, File, and FileUtils, though I suspect this will not be that usable in many cases.)
Then, to mock out that activity for a test code, simply call FileSystem.mock= :
FileSystem.mock = true
FileSystem.get_dir => FileSystem::DirAdapter
FileSystem.get_file => FileSystem::FileAdapter
FileSystem.get_file_utils => FileSystem::FileUtilsAdapter
FileSystem.get_dir.entries( '.' ) => [ '.', '..', ... ]
== HOW COMPLETE IS IT? ==
Oh dear, not at all. Hence the release name: "Beta for me, Alpha for you". I am now using it day-to-day, both at Rhizome[1] and my own blog-publishing software, Dauxite[2]. So I know it works for me. It currently handles basic issues of looking up paths, writing and reading files, modification times, etc. It doesn't know anything about symlinks, creation times, permissions. I suspect that if you tried to mock a Windows system with it, that it would squeal like a 2-year-old.
I'm putting out today's release in hopes of getting bug reports. Please file bug reports! Lots and lots of bug reports! Please be specific, though. If you file a bug titled "Support Windows, you l4m3r" I won't know where to start.
Thanks,
Francis "I'd mock out the air itself if my lungs were hot-swappable" Hwang
http://fhwang.net/
[1] Rhizome is the premier online resource in the field of new media arts: It gets more than 1 million page views a month and contains the world's largest online archive of new media art, at almost 1500 works.
[2] Dauxite is my own idiosyncratic, unreleased software. So it's not as heavily tested as Rhizome, but I use it at least once a week, so it's a good way to test something like FileSystem.