module TemporaryDirectoryContext
Provides a temporary directory context for tests that need isolated file system access.
Definitions
def around(&block)
Set up a temporary directory before the test and clean it up after.
Signature
-
yields
{|&block| ...} The test block to execute.
Implementation
def around(&block)
root = Dir.mktmpdir
begin
@root = root
super(&block)
ensure
@root = nil
# Use forced removal so cleanup tolerates paths which were already removed by the test or an external process.
FileUtils.remove_entry(root, true)
end
end
attr :root
Signature
-
attribute
String The path to the temporary directory root.