From: "Adam P. Jenkins" Date: 2005-09-21T09:41:37+09:00 Subject: Re: MockFS 0.1.2 Daniel Sheppard wrote: > Except for the fact that you can pretend you're talking to the entirety > of the filesystem from the root directory, is there much use for this > that wouldn't be met by running: > > mount -t tmpfs tmpfs /somewhere Well, tmpfs is Unix (Linux?) specific. But I would think even if you care about portability, it would be a heck of a lot simpler to just write some code that ensures that your temp directory gets deleted when your test program exits. Something like (untested code ahead): require 'fileutils' require 'tmpdir' # Creates a temp directory in the system's temp directory, arranges # for it to be deleted when the program exits, and returns the name # of the new directory. def create_temp_dir(prefix) # find a name that doesn't already exist idx = rand 10000 dir = File.join(Dir.tmpdir, prefix, idx.to_s) loop do Dir.mkdir dir break rescue Errno::EEXIST => e idx += 1 dir = File.join(Dir.tmpdir, prefix, idx.to_s) end # Arrange for dir to be deleted at program exit at_exit { FileUtils.rm_rf dir } dir end This way you're working with a real filesystem, and don't have to worry about your program behaving differently during testing due to differences between your mock filesystem implementation and a real filesystem.