module PuppetlabsSpec::Files
A support module for testing files.
Public Class Methods
cleanup()
click to toggle source
# File lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb, line 22 def self.cleanup $global_tempfiles ||= [] while (path = $global_tempfiles.pop) raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) begin FileUtils.rm_r path, secure: true rescue Errno::ENOENT # nothing to do end end end
in_tmp(path)
click to toggle source
This code exists only to support tests that run as root, pretty much. Once they have finally been eliminated this can all go… –daniel 2011-04-08
# File lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb, line 12 def self.in_tmp(path) tempdir = Dir.tmpdir Pathname.new(path).ascend do |dir| return true if File.identical?(tempdir, dir) end false end
Public Instance Methods
make_absolute(path)
click to toggle source
# File lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb, line 35 def make_absolute(path) path = File.expand_path(path) path[0] = 'c' if Puppet.features.microsoft_windows? path end
tmpdir(name)
click to toggle source
# File lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb, line 55 def tmpdir(name) path = tmpfilename(name) FileUtils.mkdir_p(path) path end
tmpfilename(name)
click to toggle source
# File lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb, line 41 def tmpfilename(name) # Generate a temporary file, just for the name... source = Tempfile.new(name) path = source.path source.close! # ...record it for cleanup, $global_tempfiles ||= [] $global_tempfiles << File.expand_path(path) # ...and bam. path end