Play in the Sandbox

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

The project is currently only on github, but it will be on RubyForge once approved. If you want to use it now, you have to use the github gems source or install it from source.

Future plans

  • Optionally Dir.chdir to the temporary directory for even easier usage
  • Supply a template directory/archive to be used for the base state of the sandbox
Brandon Dimcheff
Brandon Dimcheff
Chief Architect

Brandon Dimcheff is a software engineer born and raised in Ann Arbor, Michigan. He uses go for his day job, has fallen in love with Kubernetes, is an aspiring functional programming language nerd, and is an advocate of open source.