Module: Sus::Fixtures::TemporaryDirectoryContext
- Defined in:
- lib/sus/fixtures/temporary_directory_context.rb
Overview
Provides a temporary directory context for tests that need isolated file system access.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
- #The path to the temporary directory root.(pathtothetemporarydirectoryroot.) ⇒ Object readonly
Instance Method Summary collapse
-
#around(&block) ⇒ Object
Set up a temporary directory before the test and clean it up after.
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
31 32 33 |
# File 'lib/sus/fixtures/temporary_directory_context.rb', line 31 def root @root end |
#The path to the temporary directory root.(pathtothetemporarydirectoryroot.) ⇒ Object (readonly)
31 |
# File 'lib/sus/fixtures/temporary_directory_context.rb', line 31 attr :root |
Instance Method Details
#around(&block) ⇒ Object
Set up a temporary directory before the test and clean it up after.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sus/fixtures/temporary_directory_context.rb', line 15 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 |