1 #! /usr/bin/env ruby -S rspec
7 # A support module for testing files.
8 module PuppetSpec::Files
10 $global_tempfiles ||= []
11 while path = $global_tempfiles.pop do
14 FileUtils.rm_rf path, :secure => true
21 def make_absolute(path) PuppetSpec::Files.make_absolute(path) end
22 def self.make_absolute(path)
23 path = File.expand_path(path)
24 path[0] = 'c' if Puppet.features.microsoft_windows?
28 def tmpfile(name, dir = nil) PuppetSpec::Files.tmpfile(name, dir) end
29 def self.tmpfile(name, dir = nil)
30 # Generate a temporary file, just for the name...
31 source = dir ? Tempfile.new(name, dir) : Tempfile.new(name)
35 record_tmp(File.expand_path(path))
40 def file_containing(name, contents) PuppetSpec::Files.file_containing(name, contents) end
41 def self.file_containing(name, contents)
43 File.open(file, 'wb') { |f| f.write(contents) }
47 def tmpdir(name) PuppetSpec::Files.tmpdir(name) end
49 dir = Dir.mktmpdir(name)
56 def self.record_tmp(tmp)
57 # ...record it for cleanup,
58 $global_tempfiles ||= []
59 $global_tempfiles << tmp