unix_utils 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,9 @@
1
+ == 0.0.7 / 2012-04-11
2
+
3
+ * Bug fixes
4
+
5
+ * Make sure UnixUtils.tmp_path doesn't create too-long filenames
6
+
1
7
  == 0.0.6 / 2012-04-11
2
8
 
3
9
  * Enhancements
@@ -243,11 +243,12 @@ module UnixUtils
243
243
  end
244
244
 
245
245
  def self.tmp_path(ancestor, extname = nil) # :nodoc:
246
+ ancestor = ancestor.to_s
246
247
  extname ||= ::File.extname ancestor
247
- basename = ::File.basename ancestor.sub(/^unix_utils-[0-9]+-/, '').gsub(/\W+/, '_')
248
- name = basename + extname
248
+ basename = ::File.basename ancestor.sub(/^unix_utils-[0-9]+-/, '')
249
+ basename.gsub! /\W+/, '_'
249
250
  ::Kernel.srand
250
- ::File.join ::Dir.tmpdir, "unix_utils-#{::Kernel.rand(1e11)}-#{name}"
251
+ ::File.join ::Dir.tmpdir, "unix_utils-#{::Kernel.rand(1e11)}-#{basename[0..(231-extname.length)]}#{extname}"
251
252
  end
252
253
 
253
254
  def self.spawn(argv, options = {}) # :nodoc:
@@ -1,3 +1,3 @@
1
1
  module UnixUtils
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -401,4 +401,22 @@ describe UnixUtils do
401
401
  safe_delete outfile
402
402
  end
403
403
  end
404
+
405
+ describe :tmp_path do
406
+ it "includes basename of ancestor" do
407
+ UnixUtils.tmp_path("dirname1/dirname2/basename.extname").must_include 'basename'
408
+ end
409
+ it "includes extname of ancestor" do
410
+ UnixUtils.tmp_path("dirname1/dirname2/basename.extname").must_include 'extname'
411
+ end
412
+ it "optionally appends extname" do
413
+ File.extname(UnixUtils.tmp_path("dirname1/dirname2/basename.extname", '.foobar')).must_equal '.foobar'
414
+ end
415
+ it "doesn't create excessively long filenames" do
416
+ File.basename(UnixUtils.tmp_path("a"*5000)).length.must_equal 255
417
+ end
418
+ it "doesn't include directory part of ancestor" do
419
+ UnixUtils.tmp_path("dirname1/dirname2/basename.extname").wont_include 'dirname1'
420
+ end
421
+ end
404
422
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unix_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: