FakeFS is a Ruby library which transparently causes
FileUtils to use an in-memory. faux-filesystem rather than the real filesystem on disk. Why? So you don’t have to deal with mocking libraries, so your tests are faster, and so you don’t need a hard drive to run them.
For example, this:
def test_creates_directory FileUtils.expects(:mkdir).with("directory").once Library.add "directory" end
def test_creates_directory Library.add "directory" assert File.directory?("directory") end
I don’t know about you, but the second feels more natural to me. Also it means replacing our
mkdir call with a call to
mkdir_p won’t break our tests. Because, really, it shouldn’t.
$ rip install git://github.com/defunkt/fakefs.git
And start using it in your tests: