Skip to content

Commit a8ceafa

Browse files
committed
Fix for path-like objects
Fix #37
1 parent b27ab09 commit a8ceafa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/tmpdir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def next
149149

150150
# Generates and yields random names to create a temporary name
151151
def create(basename, tmpdir=nil, max_try: nil, **opts)
152-
origdir = tmpdir
153152
if tmpdir
153+
origdir = tmpdir = File.path(tmpdir)
154154
raise ArgumentError, "empty parent path" if tmpdir.empty?
155155
else
156156
tmpdir = tmpdir()

test/test_tmpdir.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ def test_mktmpdir_not_empty_parent
108108
assert_raise(ArgumentError) do
109109
Dir.mktmpdir("foo", "")
110110
end
111+
112+
path = Struct.new(:to_path).new("")
113+
assert_raise(ArgumentError) do
114+
Dir.mktmpdir("foo", path)
115+
end
116+
117+
Dir.mktmpdir do |d|
118+
path = Struct.new(:to_path).new(d)
119+
assert_operator(Dir.mktmpdir("prefix-", path), :start_with?, d + "/prefix-")
120+
end
111121
end
112122

113123
def assert_mktmpdir_traversal

0 commit comments

Comments
 (0)