diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/puppet_spec/files.rb | 10 | ||||
-rw-r--r-- | spec/spec_helper.rb | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 542ad6e28..aad374057 100644 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -1,9 +1,19 @@ +require 'fileutils' + # A support module for testing files. module PuppetSpec::Files def tmpfile(name) source = Tempfile.new(name) path = source.path source.close! + $tmpfiles ||= [] + $tmpfiles << path path end + + def tmpdir(name) + file = tmpfile(name) + FileUtils.mkdir_p(file) + file + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b57dab36c..16081f957 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,6 +39,20 @@ Spec::Runner.configure do |config| config.prepend_after :each do Puppet.settings.clear Puppet::Node::Environment.clear + + if defined?($tmpfiles) + $tmpfiles.each do |file| + unless file.include?("/tmp") or file.include?("/var/folders") + puts "Not deleting tmpfile #{file} outside of /tmp or /var/folders" + next + end + if FileTest.exist?(file) + system("chmod -R 755 #{file}") + system("rm -rf #{file}") + end + end + $tmpfiles.clear + end end end |