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:
1 2 3 4 5 6 7 8 9 10 |
# 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.chdirto the temporary directory for even easier usage - Supply a template directory/archive to be used for the base state of the sandbox
About this entry
- Published:
- February 14th 01:48 AM
- Updated:
- February 14th 11:23 AM
- Sections:
- Projects
- Tags:
- filesystem, ruby, sandbox, test
- By:
- brandon.dimcheff
0 comments
Jump to comment form | comments rss [?]