I’ve got a document management system which I programmed in Rails 2.3.8 a while ago and I’ve been retrofitting some rspec tests to the project before refactoring and making enhancements.
The problem is a lot of my tests require stubbing out most of the File & FileUtils libraries as there is a lot of file interaction within models. Is there a better way to test File & Directory actions without having to touch the filesystem at all?
For instance I stub out mkdir_p:
FileUtils.stub!(:mkdir_p)
And when I’m moving I use something like this:
FileUtils.should_receive(:mv).with("from path","to path")
Use fakefs. It’s perfect for the purpose.