summaryrefslogtreecommitdiff
path: root/test/test_pstore.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-08 14:52:13 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-08 14:52:13 +0000
commitb8b5f5d437e6e7266e06f5d7c526553f39278590 (patch)
tree2f808ecec199bd1b8d34d7bbd99838b9d278e1ba /test/test_pstore.rb
parent1fd41dce10a93ce89a098ffc33f40d5243f5e140 (diff)
Generate temporary file in tmpdir.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_pstore.rb')
-rw-r--r--test/test_pstore.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/test/test_pstore.rb b/test/test_pstore.rb
index e8a1032..8bb44e8 100644
--- a/test/test_pstore.rb
+++ b/test/test_pstore.rb
@@ -1,10 +1,11 @@
require 'test/unit'
require 'pstore'
+require 'tmpdir'
require_relative 'ruby/envutil'
class PStoreTest < Test::Unit::TestCase
def setup
- @pstore_file = "pstore.tmp.#{Process.pid}"
+ @pstore_file = File.join(Dir.tmpdir, "pstore.tmp.#{Process.pid}")
@pstore = PStore.new(@pstore_file)
end
@@ -87,7 +88,7 @@ class PStoreTest < Test::Unit::TestCase
@pstore.transaction {}
end
assert_block do
- pstore = PStore.new("pstore.tmp2.#{Process.pid}",true)
+ pstore = PStore.new(second_file, true)
flag = false
Thread.new do
pstore.transaction do
@@ -98,18 +99,21 @@ class PStoreTest < Test::Unit::TestCase
end
until flag; end
pstore.transaction { pstore[:foo] == "bar" }
- File.unlink("pstore.tmp2.#{Process.pid}") rescue nil
end
+ ensure
+ File.unlink(second_file) rescue nil
end
def test_nested_transaction_raises_error
assert_raise(PStore::Error) do
@pstore.transaction { @pstore.transaction { } }
end
- pstore = PStore.new("pstore.tmp2.#{Process.pid}", true)
+ pstore = PStore.new(second_file, true)
assert_raise(PStore::Error) do
pstore.transaction { pstore.transaction { } }
end
+ ensure
+ File.unlink(second_file) rescue nil
end
# Test that PStore's file operations do not blow up when default encodings are set
@@ -126,4 +130,8 @@ class PStoreTest < Test::Unit::TestCase
SRC
assert_equal(bug5311, @pstore.transaction {@pstore["Bug5311"]}, bug5311)
end
+
+ def second_file
+ File.join(Dir.tmpdir, "pstore.tmp2.#{Process.pid}")
+ end
end