Tmptation provides classes that help safely manipulate temporary files and directories. Especially useful for use in tests.
- easy garbage collection of all created tmp files and dirs with
- safe deletion - will refuse to delete non-tmp paths (as determined by
# TmpFile is a subclass of Tempfile, with a few additions file = Tmptation::TmpFile.new('name', 'contents') file.path.exist? #=> true file.closed? #=> false file.read #=> "contents" Tmptation::TmpFile.delete_all file.path.exist? #=> false file.closed? #=> true # TmpDir behaves like Pathname, with a few additions path = Tmptation::TmpDir.new path.exist? #=> true Tmptation::TmpDir.delete_all path.exist? #=> false
Tmptation also contains two mixins,
They might be useful on their own. See the inline docs for more details.
If you use Tmptation in tests, add
to your global teardown method:
class MiniTest::Unit::TestCase def teardown TmpFile.delete_all TmpDir.delete_all end end