Skip to content

Commit aa12eb5

Browse files
committed
Remove deprecated File.exists?
In 7999ff2 the cops were disabled, but Ruby 3.2 has removed the method.
1 parent b3f473f commit aa12eb5

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

lib/puppet/parser/functions/load_module_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Puppet::Parser::Functions
2222
module_path = function_get_module_path([mod])
2323
metadata_json = File.join(module_path, 'metadata.json')
2424

25-
metadata_exists = File.exists?(metadata_json) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
25+
metadata_exists = File.exist?(metadata_json)
2626
if metadata_exists
2727
metadata = PSON.load(File.read(metadata_json))
2828
else

lib/puppet/parser/functions/loadjson.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module Puppet::Parser::Functions
5050
args[1]
5151
end
5252
PSON.load(contents) || args[1]
53-
elsif File.exists?(args[0]) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
53+
elsif File.exist?(args[0])
5454
content = File.read(args[0])
5555
PSON.load(content) || args[1]
5656
else

lib/puppet/parser/functions/loadyaml.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module Puppet::Parser::Functions
4949
args[1]
5050
end
5151
YAML.safe_load(contents) || args[1]
52-
elsif File.exists?(args[0]) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
52+
elsif File.exist?(args[0])
5353
YAML.load_file(args[0]) || args[1]
5454
else
5555
warning("Can't load '#{args[0]}' File does not exist!")

spec/functions/load_module_metadata_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
it 'jsons parse the file' do
3131
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
32-
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
32+
allow(File).to receive(:exist?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
3333
allow(File).to receive(:read).with("#{prefix}/path/to/module/metadata.json").and_return('{"name": "spencer-science"}')
3434

3535
result = subject.execute('science')
@@ -38,13 +38,13 @@
3838

3939
it 'fails by default if there is no metadata.json' do
4040
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
41-
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
41+
allow(File).to receive(:exist?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
4242
expect { subject.call(['science']) }.to raise_error(Puppet::ParseError)
4343
end
4444

4545
it 'returns nil if user allows empty metadata.json' do
4646
allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
47-
allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
47+
allow(File).to receive(:exist?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
4848
result = subject.execute('science', true)
4949
expect(result).to eq({})
5050
end

spec/functions/loadjson_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
before(:each) do
29-
allow(File).to receive(:exists?).with(filename).and_return(false).once
29+
allow(File).to receive(:exist?).with(filename).and_return(false).once
3030
allow(PSON).to receive(:load).never
3131
end
3232
it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
@@ -46,7 +46,7 @@
4646
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
4747

4848
before(:each) do
49-
allow(File).to receive(:exists?).with(filename).and_return(true).once
49+
allow(File).to receive(:exist?).with(filename).and_return(true).once
5050
allow(File).to receive(:read).with(filename).and_return(json).once
5151
allow(File).to receive(:read).with(filename).and_return(json).once
5252
allow(PSON).to receive(:load).with(json).and_return(data).once
@@ -65,7 +65,7 @@
6565
let(:json) { '{"key":"value"}' }
6666

6767
before(:each) do
68-
allow(File).to receive(:exists?).with(filename).and_return(true).once
68+
allow(File).to receive(:exist?).with(filename).and_return(true).once
6969
allow(File).to receive(:read).with(filename).and_return(json).once
7070
allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
7171
end

spec/functions/loadyaml_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let(:filename) { '/tmp/doesnotexist' }
1111

1212
it "'default' => 'value'" do
13-
expect(File).to receive(:exists?).with(filename).and_return(false).once
13+
expect(File).to receive(:exist?).with(filename).and_return(false).once
1414
expect(YAML).to receive(:load_file).never
1515
is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
1616
end
@@ -21,7 +21,7 @@
2121
let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } }
2222

2323
it "returns 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'" do
24-
expect(File).to receive(:exists?).with(filename).and_return(true).once
24+
expect(File).to receive(:exist?).with(filename).and_return(true).once
2525
expect(YAML).to receive(:load_file).with(filename).and_return(data).once
2626
is_expected.to run.with_params(filename).and_return(data)
2727
end
@@ -31,7 +31,7 @@
3131
let(:filename) { '/tmp/doesexist' }
3232

3333
it 'filename /tmp/doesexist' do
34-
expect(File).to receive(:exists?).with(filename).and_return(true).once
34+
expect(File).to receive(:exist?).with(filename).and_return(true).once
3535
allow(YAML).to receive(:load_file).with(filename).once.and_raise(StandardError, 'Something terrible have happened!')
3636
is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
3737
end

0 commit comments

Comments
 (0)