I needed to test some code that reads and writes files on the filesystem. I got sick of manually setting up a scratch area for my test files and cleaning them up when I was done, so I created Sandbox to keep my tests DRY.
See the Sandbox readme for more information, but the basic idea is this:
# inside a test somewhere Sandbox.play do |path| file = File.join(path, 'foo') FileUtils.touch(file) # build a sand castle assert File.exists?(file) # test whatever you want in here end assert !File.exists?(file) # path has been deleted
Dir.chdirto the temporary directory for even easier usage
- Supply a template directory/archive to be used for the base state of the sandbox