diff --git a/spec/lib/gitlab/bare_repository_import/importer_spec.rb b/spec/lib/gitlab/bare_repository_import/importer_spec.rb
index b0d721a74cef1e789d7b9fa2ef681985e5818bf6..bbf8d81b251f9ba7c1e62288114f6f8869f60ba1 100644
--- a/spec/lib/gitlab/bare_repository_import/importer_spec.rb
+++ b/spec/lib/gitlab/bare_repository_import/importer_spec.rb
@@ -193,8 +193,6 @@
   def prepare_repository(project_path, source_project)
     repo_path = File.join(base_dir, project_path)
 
-    return create_bare_repository(repo_path) unless source_project
-
     cmd = %W(#{Gitlab.config.git.bin_path} clone --bare #{source_project} #{repo_path})
 
     system(git_env, *cmd, chdir: SEED_STORAGE_PATH, out: '/dev/null', err: '/dev/null')
diff --git a/spec/lib/gitlab/bare_repository_import/repository_spec.rb b/spec/lib/gitlab/bare_repository_import/repository_spec.rb
index bf115046744b8fafa229603163b815711e520b12..d29447ee3760dcc68e9f258c4a44364b2450f252 100644
--- a/spec/lib/gitlab/bare_repository_import/repository_spec.rb
+++ b/spec/lib/gitlab/bare_repository_import/repository_spec.rb
@@ -59,18 +59,15 @@
     let(:root_path) { TestEnv.repos_path }
     let(:repo_path) { File.join(root_path, "#{hashed_path}.git") }
     let(:wiki_path) { File.join(root_path, "#{hashed_path}.wiki.git") }
+    let(:raw_repository) { Gitlab::Git::Repository.new('default', "#{hashed_path}.git", nil, nil) }
 
     before do
-      TestEnv.create_bare_repository(repo_path)
-
-      Gitlab::GitalyClient::StorageSettings.allow_disk_access do
-        repository = Rugged::Repository.new(repo_path)
-        repository.config['gitlab.fullpath'] = 'to/repo'
-      end
+      raw_repository.create_repository
+      raw_repository.set_full_path(full_path: 'to/repo')
     end
 
     after do
-      FileUtils.rm_rf(repo_path)
+      raw_repository.remove
     end
 
     subject { described_class.new(root_path, repo_path) }
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index cd1e629e1d2611813cf95458c4a4027efd79a9d8..9e98d13f67feaf5f6a4095edb5c94b7aa40a9be6 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -543,15 +543,15 @@ def wiki_repo(project)
       end
 
       context 'with legacy storage' do
-        let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
+        let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', File.join(user.namespace.full_path, 'existing.git'), nil, nil) }
 
         before do
           stub_application_setting(hashed_storage_enabled: false)
-          TestEnv.create_bare_repository(fake_repo_path)
+          raw_fake_repo.create_repository
         end
 
         after do
-          FileUtils.rm_rf(fake_repo_path)
+          raw_fake_repo.remove
         end
 
         it 'does not allow to create a project when path matches existing repository on disk' do
@@ -578,15 +578,15 @@ def wiki_repo(project)
       context 'with hashed storage' do
         let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
         let(:hashed_path) { '@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
-        let(:fake_repo_path) { File.join(TestEnv.repos_path, "#{hashed_path}.git") }
+        let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', "#{hashed_path}.git", nil, nil) }
 
         before do
           allow(Digest::SHA2).to receive(:hexdigest) { hash }
-          TestEnv.create_bare_repository(fake_repo_path)
+          raw_fake_repo.create_repository
         end
 
         after do
-          FileUtils.rm_rf(fake_repo_path)
+          raw_fake_repo.remove
         end
 
         it 'does not allow to create a project when path matches existing repository on disk' do
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index ce30a20edf4b09e7b27d080109f8ebc79fad1063..e292c13c46e0e40142583facd43d4f44413bdd6b 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -156,16 +156,16 @@
       end
 
       context 'repository in legacy storage already exists' do
-        let(:fake_repo_path) { File.join(TestEnv.repos_path, @to_user.namespace.full_path, "#{@from_project.path}.git") }
+        let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', File.join(@to_user.namespace.full_path, "#{@from_project.path}.git"), nil, nil) }
         let(:params) { { namespace: @to_user.namespace, using_service: true } }
 
         before do
           stub_application_setting(hashed_storage_enabled: false)
-          TestEnv.create_bare_repository(fake_repo_path)
+          raw_fake_repo.create_repository
         end
 
         after do
-          FileUtils.rm_rf(fake_repo_path)
+          raw_fake_repo.remove
         end
 
         subject { fork_project(@from_project, @to_user, params) }
diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb
index bebe80b710bf0623d1844eae993620bcc60a759d..ff271d804f3f7b0d2a4e94fc6881e2e768d2eee4 100644
--- a/spec/services/projects/transfer_service_spec.rb
+++ b/spec/services/projects/transfer_service_spec.rb
@@ -372,16 +372,16 @@ def current_path
   end
 
   context 'namespace which contains orphan repository with same projects path name' do
-    let(:fake_repo_path) { File.join(TestEnv.repos_path, group.full_path, "#{project.path}.git") }
+    let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', File.join(group.full_path, "#{project.path}.git"), nil, nil) }
 
     before do
       group.add_owner(user)
 
-      TestEnv.create_bare_repository(fake_repo_path)
+      raw_fake_repo.create_repository
     end
 
     after do
-      FileUtils.rm_rf(fake_repo_path)
+      raw_fake_repo.remove
     end
 
     it 'does not allow the project transfer' do
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index a5e771047358f15b18f2e821ba8ecb85b8441878..1241491d91421480dbeb56cd8b8c35155be20585 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -348,17 +348,17 @@
     end
 
     context 'when renaming a project' do
-      let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
+      let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', File.join(user.namespace.full_path, 'existing.git'), nil, nil) }
 
       context 'with legacy storage' do
         let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
 
         before do
-          TestEnv.create_bare_repository(fake_repo_path)
+          raw_fake_repo.create_repository
         end
 
         after do
-          FileUtils.rm_rf(fake_repo_path)
+          raw_fake_repo.remove
         end
 
         it 'does not allow renaming when new path matches existing repository on disk' do
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index 7c865dd7e1188f0db8c307d93d6185c2ec744b5e..59e6f54cf45ef4651790890bfa313fef03e50e96 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -310,14 +310,6 @@ def storage_dir_exists?(storage, dir)
     end
   end
 
-  def create_bare_repository(path)
-    FileUtils.mkdir_p(path)
-
-    system(git_env, *%W(#{Gitlab.config.git.bin_path} -C #{path} init --bare),
-           out: '/dev/null',
-           err: '/dev/null')
-  end
-
   def repos_path
     @repos_path ||= GitalySetup.repos_path
   end