Please review pull request #47: (#13600) Monkey patch mktmpdir on ruby 1.8.5 opened by (haus)
Description:
The yaml_backend spec test uses mktmpdir in its tests, which is not available
on ruby 1.8.5. This fix defines mktmpdir using the 1.8.7 method if the method
is not available, as is the case in ruby 1.8.5. It defines the method if needed
in the spec_helper file, and the requires in the yaml_backend_spec are
reordered to ensure that spec_helper is required last, so that it will know if
mktmpdir needs to be defined.
- Opened: Wed May 02 17:53:14 UTC 2012
- Based on: puppetlabs:master (6bd7122cf4f6d3a97168acc0adf7f0613ab7b8a5)
- Requested merge: haus:ticket/master/13600_fix_specs_on_ruby_1_8_5 (24ef7b90bfba1405d2419fc84befe1c273ddd826)
Diff follows:
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index f64c64e..2fea865 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -17,3 +17,46 @@ class Functions
end
end
+# In ruby 1.8.5 Dir does not have mktmpdir defined, so this monkey patches
+# Dir to include the 1.8.7 definition of that method if it isn't already defined.
+# Method definition borrowed from ruby-1.8.7-p357/lib/ruby/1.8/tmpdir.rb
+unless Dir.respond_to?(:mktmpdir)
+ def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
+ case prefix_suffix
+ when nil
+ prefix = "d"
+ suffix = ""
+ when String
+ prefix = prefix_suffix
+ suffix = ""
+ when Array
+ prefix = prefix_suffix[0]
+ suffix = prefix_suffix[1]
+ else
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
+ end
+ tmpdir ||= Dir.tmpdir
+ t = Time.now.strftime("%Y%m%d")
+ n = nil
+ begin
+ path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
+ path << "-#{n}" if n
+ path << suffix
+ Dir.mkdir(path, 0700)
+ rescue Errno::EEXIST
+ n ||= 0
+ n += 1
+ retry
+ end
+
+ if block_given?
+ begin
+ yield path
+ ensure
+ FileUtils.remove_entry_secure path
+ end
+ else
+ path
+ end
+ end
+end
diff --git a/spec/unit/backend/yaml_backend_spec.rb b/spec/unit/backend/yaml_backend_spec.rb
index 7514ec9..9ee70ee 100644
--- a/spec/unit/backend/yaml_backend_spec.rb
+++ b/spec/unit/backend/yaml_backend_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
require 'tmpdir'
require 'hiera/backend/yaml_backend'
require 'fileutils'
+require 'spec_helper'
class Hiera
module Backend
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
