Skip to content

Commit caea941

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

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
@@ -23,7 +23,7 @@ module Puppet::Parser::Functions
2323
module_path = function_get_module_path([mod])
2424
metadata_json = File.join(module_path, 'metadata.json')
2525

26-
metadata_exists = File.exists?(metadata_json) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
26+
metadata_exists = File.exist?(metadata_json)
2727
if metadata_exists
2828
metadata = if Puppet::Util::Package.versioncmp(Puppet.version, '8.0.0').negative?
2929
PSON.load(File.read(metadata_json))

lib/puppet/parser/functions/loadjson.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module Puppet::Parser::Functions
5555
else
5656
JSON.parse(contents) || args[1]
5757
end
58-
elsif File.exists?(args[0]) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
58+
elsif File.exist?(args[0])
5959
content = File.read(args[0])
6060
if Puppet::Util::Package.versioncmp(Puppet.version, '8.0.0').negative?
6161
PSON.load(content) || args[1]

lib/puppet/parser/functions/loadyaml.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
YAML.safe_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
YAML.load_file(args[0]) || args[1]
5555
else
5656
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
if Puppet::PUPPETVERSION[0].to_i < 8
3131
allow(PSON).to receive(:load).never # rubocop:disable RSpec/ReceiveNever Switching to not_to receive breaks testing in this case
3232
else
@@ -51,7 +51,7 @@
5151
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
5252

5353
before(:each) do
54-
allow(File).to receive(:exists?).with(filename).and_return(true).once
54+
allow(File).to receive(:exist?).with(filename).and_return(true).once
5555
allow(File).to receive(:read).with(filename).and_return(json).once
5656
allow(File).to receive(:read).with(filename).and_return(json).once
5757
if Puppet::PUPPETVERSION[0].to_i < 8
@@ -75,7 +75,7 @@
7575
let(:json) { '{"key":"value"}' }
7676

7777
before(:each) do
78-
allow(File).to receive(:exists?).with(filename).and_return(true).once
78+
allow(File).to receive(:exist?).with(filename).and_return(true).once
7979
allow(File).to receive(:read).with(filename).and_return(json).once
8080
if Puppet::PUPPETVERSION[0].to_i < 8
8181
allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'

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).not_to receive(:load_file)
1515
expect(subject).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
expect(subject).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
expect(subject).to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
3737
end

0 commit comments

Comments
 (0)