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

>From the sparse documentation for tmpfs, I don't know if I'm entirely
clear on its usage. However, it appears to me that you'd use tmpfs to
mount a new filesystem alongside the ones you've already got. I can see
how this would be useful in many cases, but the problem I wanted to
address with MockFS was one of having lots of files all over the place.

For example, a well-factored system might have a bunch of classes
looking like this:

class DiskCache
  @@cache_path = '/tmp/disk_cache.yml'
  ...
end

class WelcomeToOurWebsiteEmail
  @@template = '/var/www/email_templates/welcome.tmpl'
  @@log_file = '/var/log/email.log'
  ...
end

etc, etc. If all those files lived in the same place, you might be able
to use tmpfs to put them somewhere neat and unmount it at the end. But
in my experience, non-trivial systems have files that need to live in
different places for different reasons, and you'd rather not have to
change those just to make testing easier.

Another issue is one of safety; you'd rather have real-life logs or
other files unaffected by your test cases. In running my tests, I'd
rather play it safe and create a mock file system that lets me write to
whatever file locations I want, and then just GCs the results when the
tests stop running.

Of course, there are pretty obvious tradeoffs; MockFS is still far from
complete, and using it introduces extra verbosity into your production
code. I personally think the tradeoffs are okay because I write lots of
tests -- more than 600 on the primary codebase at my day job -- so
already I think MockFS has been worth it for me.

F.