From b8b5f5d437e6e7266e06f5d7c526553f39278590 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 8 Dec 2011 14:52:13 +0000 Subject: Generate temporary file in tmpdir. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_pstore.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/test_pstore.rb b/test/test_pstore.rb index e8a1032c98..8bb44e8a51 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 -- cgit v1.2.3