fhwang.net

FileSystem 0.1.0

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.

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 and my own blog-publishing software, Dauxite. 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.

blog comments powered by Disqus
Tagged: ruby

« Previous post

Next post »