Stubbing `File#open` ties you to a specific implementation. Consider using real files instead; Ruby provides a [`Tempfile` class](http://www.ruby-doc.org/stdlib-2.0/libdoc/tempfile/rdoc/Tempfile.html) that will probably help you here.