Tmptation is a project mainly written in Ruby, based on the MIT license.
Classes that help safely manipulate temporary files and directories
Tmptation provides classes that help safely manipulate temporary files and directories. Especially useful for use in tests.
.delete_all
Dir.tmpdir
)# 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, SafeDeletable
and SubclassTracking
.
They might be useful on their own. See the inline docs for more details.
If you use Tmptation in tests, add TmpFile.delete_all
and TmpDir.delete_all
to your global teardown method:
class MiniTest::Unit::TestCase
def teardown
TmpFile.delete_all
TmpDir.delete_all
end
end