fhwang.net

MockFS 0.1.2

MockFS lumbers forward with its newest release, 0.1.2. Besides a liberal heaping of bugfixes, this version adds override.rb, which does some convenient but possibly dangerous redefining of global constants and methods. Ooh, danger!

What’s MockFS?

MockFS is nothing less than an attempt to simulate a file system in memory for the purposes of testing. I wrote it for my own use, because I write lots of tests and sometimes I get sick of cleaning up test files. It’s a lot simpler to just simulate the disk in memory and drop the whole thing when you’re done with your test.

It’s not complete by a longshot, but it’s complete enough that I’m able to use it to help me write tests for production code—most notably, for Rhizome.org, a community website that gets more than a million pageviews a month.

What’s new in 0.1.2?

  • First, a lot of little things have been fixed. MockFS now has a better understanding of file permissions, of paths, and the multiple ways that File, FileUtils, and Dir allow the same method to be called through class or instance methods.
  • I’ve also added override.rb, which redefines File, FileUtils, and Dir. This is so your code doesn’t have to reference MockFS directly; the test cases can include override.rb and reference the mock file system that way.

override.rb also includes a redefinition of Kernel.require, so that if a file doesn’t exist in the real file system, Kernel.require will look for it in the mock file system. This might be useful in cases where you have configuration files written in Ruby, and would like to swap them out during testing.

Pretty much everything in override.rb is experimental, so I’d urge caution in including the file.

blog comments powered by Disqus
Tagged: ruby

« Previous post

Next post »