summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-30 14:17:14 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit274d1c5e78250640b8d2c40201ca2586c0088f32 (patch)
tree239a22bd3c5eb40610e2ed810df96ceeb392590b /spec
parent7089446697ad550c22012bc2b5572030727d67e1 (diff)
downloadpuppet-274d1c5e78250640b8d2c40201ca2586c0088f32.tar.gz
puppet-274d1c5e78250640b8d2c40201ca2586c0088f32.tar.xz
puppet-274d1c5e78250640b8d2c40201ca2586c0088f32.zip
Adding tmpfile cleanup to tests
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/puppet_spec/files.rb10
-rw-r--r--spec/spec_helper.rb14
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