From 87eccec9de14ae4551ea1fd19e07a6ac8613994a Mon Sep 17 00:00:00 2001 From: Sharon Rosner Date: Fri, 22 Dec 2023 09:40:09 +0100 Subject: [PATCH] Use Tempfile for temporary file names in tests --- test/test_database.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/test_database.rb b/test/test_database.rb index 4c62f33..1df9167 100644 --- a/test/test_database.rb +++ b/test/test_database.rb @@ -331,7 +331,7 @@ def test_database_limit end def test_database_busy_timeout - fn = "/tmp/extralite-#{rand(10000)}.db" + fn = Tempfile.new('extralite_test_database_busy_timeout').path db1 = Extralite::Database.new(fn) db2 = Extralite::Database.new(fn) @@ -441,7 +441,7 @@ def test_string_encoding end def test_database_transaction_commit - path = Tempfile.new('extralite_transaction_commit').path + path = Tempfile.new('extralite_test_database_transaction_commit').path db1 = Extralite::Database.new(path) db2 = Extralite::Database.new(path) @@ -495,7 +495,8 @@ def test_database_transaction_rollback class ScenarioTest < MiniTest::Test def setup - @db = Extralite::Database.new('/tmp/extralite.db') + @fn = Tempfile.new('extralite_scenario_test').path + @db = Extralite::Database.new(@fn) @db.query('create table if not exists t (x,y,z)') @db.query('delete from t') @db.query('insert into t values (1, 2, 3)') @@ -505,7 +506,7 @@ def setup def test_concurrent_transactions done = false t = Thread.new do - db = Extralite::Database.new('/tmp/extralite.db') + db = Extralite::Database.new(@fn) db.query 'begin immediate' sleep 0.01 until done @@ -613,7 +614,7 @@ def test_backup_with_schema_names end def test_backup_with_fn - tmp_fn = "/tmp/#{rand(86400)}.db" + tmp_fn = Tempfile.new('extralite_test_backup_with_fn').path @src.backup(tmp_fn) db = Extralite::Database.new(tmp_fn)