Skip to content

Commit 0977588

Browse files
committed
Replace global variable with environment variable
1 parent 369e933 commit 0977588

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

spec/octocatalog-diff/tests/util/parallel_spec.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
require 'logger'
66
require 'parallel'
77

8-
# rubocop:disable Style/GlobalVars
98
describe OctocatalogDiff::Util::Parallel do
109
before(:each) do
11-
$octocatalog_diff_util_parallel_spec_tempdir = Dir.mktmpdir
10+
ENV['OCTOCATALOG_DIFF_TEMPDIR'] = Dir.mktmpdir
1211
end
1312

1413
after(:each) do
15-
OctocatalogDiff::Spec.clean_up_tmpdir($octocatalog_diff_util_parallel_spec_tempdir)
14+
OctocatalogDiff::Spec.clean_up_tmpdir(ENV['OCTOCATALOG_DIFF_TEMPDIR'])
15+
ENV.delete('OCTOCATALOG_DIFF_TEMPDIR')
1616
end
1717

1818
context 'with parallel processing' do
@@ -50,13 +50,13 @@ def two(arg, _logger = nil)
5050
it 'should handle a task that fails after other successes' do
5151
class Foo
5252
def one(arg, _logger = nil)
53-
File.open(File.join($octocatalog_diff_util_parallel_spec_tempdir, 'one'), 'w') { |f| f.write '' }
53+
File.open(File.join(ENV['OCTOCATALOG_DIFF_TEMPDIR'], 'one'), 'w') { |f| f.write '' }
5454
'one ' + arg
5555
end
5656

5757
def two(_arg, _logger = nil)
5858
100.times do
59-
break if File.file?(File.join($octocatalog_diff_util_parallel_spec_tempdir, 'one'))
59+
break if File.file?(File.join(ENV['OCTOCATALOG_DIFF_TEMPDIR'], 'one'))
6060
sleep 0.1
6161
end
6262
# Sometimes the system will still handle the second process if it's near-simultaneous
@@ -90,7 +90,7 @@ def two(_arg, _logger = nil)
9090
class Foo
9191
def one(arg, _logger = nil)
9292
sleep 10
93-
File.open(File.join($octocatalog_diff_util_parallel_spec_tempdir, 'one'), 'w') { |f| f.write '' }
93+
File.open(File.join(ENV['OCTOCATALOG_DIFF_TEMPDIR'], 'one'), 'w') { |f| f.write '' }
9494
'one ' + arg
9595
end
9696

@@ -119,7 +119,7 @@ def two(_arg, _logger = nil)
119119
expect(two_result.exception).to be_a_kind_of(RuntimeError)
120120
expect(two_result.exception.message).to eq('Two failed')
121121

122-
expect(File.file?(File.join($octocatalog_diff_util_parallel_spec_tempdir, 'one'))).to eq(false)
122+
expect(File.file?(File.join(ENV['OCTOCATALOG_DIFF_TEMPDIR'], 'one'))).to eq(false)
123123
end
124124

125125
it 'should log debug messages' do
@@ -480,4 +480,3 @@ def validate(arg, _logger = nil, _extra_args = {})
480480
end
481481
end
482482
end
483-
# rubocop:enable Style/GlobalVars

0 commit comments

Comments
 (0)