From 1294290d6045fdd383a17cb45039b671ab954f05 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 27 Jun 2018 22:33:00 -0700 Subject: Update for pdk test unit Add tmpfile helper --- spec/unit/provider/augeas/augeas_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb index 51a734d..f7358ba 100644 --- a/spec/unit/provider/augeas/augeas_spec.rb +++ b/spec/unit/provider/augeas/augeas_spec.rb @@ -22,6 +22,23 @@ describe provider_class do File.expand_path(File.join(File.dirname(__FILE__), '../../../fixtures/unit/provider/augeas/augeas')) end + def tmpfile(name) + Puppet::FileSystem.expand_path(make_tmpname(name, nil).encode(Encoding::UTF_8), Dir.tmpdir) + end + + # Copied from ruby 2.4 source + def make_tmpname((prefix, suffix), n) + prefix = (String.try_convert(prefix) or + raise ArgumentError, "unexpected prefix: #{prefix.inspect}") + suffix &&= (String.try_convert(suffix) or + raise ArgumentError, "unexpected suffix: #{suffix.inspect}") + t = Time.now.strftime("%Y%m%d") + path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup + path << "-#{n}" if n + path << suffix if suffix + path + end + describe "command parsing" do it "should break apart a single line into three tokens and clean up the context" do @resource[:context] = "/context" @@ -821,8 +838,8 @@ describe provider_class do it "should not clobber the file if it's a symlink" do Puppet::Util::Storage.stubs(:store) - link = Tempfile.new('link') - target = Tempfile.new('target') + link = tmpfile('link') + target = tmpfile('target') FileUtils.touch(target) Puppet::FileSystem.symlink(target, link) -- cgit v1.2.3