unix_utils 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/unix_utils.rb +4 -3
- data/lib/unix_utils/version.rb +1 -1
- data/test/test_unix_utils.rb +18 -0
- metadata +1 -1
data/History.txt
CHANGED
data/lib/unix_utils.rb
CHANGED
@@ -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]+-/, '')
|
248
|
-
|
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)}-#{
|
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:
|
data/lib/unix_utils/version.rb
CHANGED
data/test/test_unix_utils.rb
CHANGED
@@ -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
|