From 6f35244defbb410373a9ffca8468ab482800ffd9 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 27 Jul 2019 12:37:09 +0900 Subject: Do not use the same temp file in different tests It causes unexpected results when running tests in parallel. Ref: https://buildkite.com/rails/rails/builds/62610#0165f6d9-b9c8-4948-9319-07b58bfbfd4f/989-998 --- railties/test/commands/credentials_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/commands/credentials_test.rb b/railties/test/commands/credentials_test.rb index 562e2ec382..3dec6fbe10 100644 --- a/railties/test/commands/credentials_test.rb +++ b/railties/test/commands/credentials_test.rb @@ -5,6 +5,7 @@ require "env_helpers" require "rails/command" require "rails/commands/credentials/credentials_command" require "fileutils" +require "tempfile" class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation, EnvHelpers @@ -110,7 +111,7 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase end test "edit ask the user to opt in to pretty credentials, user accepts" do - file = File.open("foo", "w") + file = Tempfile.open("credentials_test") file.write("y") file.rewind @@ -127,11 +128,11 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase assert_equal("bin/rails credentials:show\n", `git config --get 'diff.rails_credentials.textconv'`) end ensure - File.delete(file) + file.close! end test "edit ask the user to opt in to pretty credentials, user refuses" do - file = File.open("foo", "w") + file = Tempfile.open("credentials_test") file.write("n") file.rewind @@ -140,7 +141,7 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase git_attributes = app_path(".gitattributes") assert_not(File.exist?(git_attributes)) ensure - File.delete(file) + file.close! end test "show credentials" do -- cgit v1.2.3