Sandbox is a very small library that creates a folder in tmp for you to be able to perform tests. Your temporary path will be available while the play block is executing. When you’re done, it will clean it up for you.
Sandbox.play do |path| FileUtils.touch(File.join(path, 'foo')) end # path has been deleted
It will clean up even if you have an exception:
Sandbox.play do |path| # do stuff in path raise "boom" end # path has been deleted
You can also use the Sandbox object directly if necessary:
sbox = Sandbox.new # do stuff sbox.close # deletes sandbox
This could be useful for RSpec:
before(:each) do @sbox = Sandbox.new end after(:each) do @sbox.close end # specs using @sbox (with a new sandbox for each spec)
Copyright © 2009 Brandon Dimcheff. See LICENSE for details.