diff options
-rw-r--r-- | lib/chef/provider/file.rb | 4 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 10 | ||||
-rw-r--r-- | spec/unit/provider/apt_update_spec.rb | 4 |
3 files changed, 7 insertions, 11 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 59724a8340..96f6eef061 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -157,7 +157,7 @@ class Chef end action :delete do - if ::File.exists?(new_resource.path) + if ::File.exist?(new_resource.path) converge_by("delete file #{new_resource.path}") do do_backup unless file_class.symlink?(new_resource.path) ::File.delete(new_resource.path) @@ -393,7 +393,7 @@ class Chef # a nil tempfile is okay, means the resource has no content or no new content return if tempfile.nil? # but a tempfile that has no path or doesn't exist should not happen - if tempfile.path.nil? || !::File.exists?(tempfile.path) + if tempfile.path.nil? || !::File.exist?(tempfile.path) raise "#{ChefUtils::Dist::Infra::CLIENT} is confused, trying to deploy a file that has no path or does not exist..." end diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index dccfd5d027..3a717e91c1 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -43,7 +43,6 @@ end def setup_normal_file [ resource_path, normalized_path, windows_path].each do |path| allow(File).to receive(:file?).with(path).and_return(true) - allow(File).to receive(:exists?).with(path).and_return(true) allow(File).to receive(:exist?).with(path).and_return(true) allow(File).to receive(:directory?).with(path).and_return(false) allow(File).to receive(:writable?).with(path).and_return(true) @@ -57,7 +56,6 @@ def setup_missing_file [ resource_path, normalized_path, windows_path].each do |path| allow(File).to receive(:file?).with(path).and_return(false) allow(File).to receive(:realpath?).with(path).and_return(resource_path) - allow(File).to receive(:exists?).with(path).and_return(false) allow(File).to receive(:exist?).with(path).and_return(false) allow(File).to receive(:directory?).with(path).and_return(false) allow(File).to receive(:writable?).with(path).and_return(false) @@ -70,7 +68,6 @@ def setup_symlink [ resource_path, normalized_path, windows_path].each do |path| allow(File).to receive(:file?).with(path).and_return(true) allow(File).to receive(:realpath?).with(path).and_return(normalized_path) - allow(File).to receive(:exists?).with(path).and_return(true) allow(File).to receive(:exist?).with(path).and_return(true) allow(File).to receive(:directory?).with(path).and_return(false) allow(File).to receive(:writable?).with(path).and_return(true) @@ -84,7 +81,6 @@ def setup_unwritable_file [ resource_path, normalized_path, windows_path].each do |path| allow(File).to receive(:file?).with(path).and_return(false) allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT) - allow(File).to receive(:exists?).with(path).and_return(true) allow(File).to receive(:exist?).with(path).and_return(true) allow(File).to receive(:directory?).with(path).and_return(false) allow(File).to receive(:writable?).with(path).and_return(false) @@ -97,7 +93,6 @@ def setup_missing_enclosing_directory [ resource_path, normalized_path, windows_path].each do |path| allow(File).to receive(:file?).with(path).and_return(false) allow(File).to receive(:realpath?).with(path).and_raise(Errno::ENOENT) - allow(File).to receive(:exists?).with(path).and_return(false) allow(File).to receive(:exist?).with(path).and_return(false) allow(File).to receive(:directory?).with(path).and_return(false) allow(File).to receive(:writable?).with(path).and_return(false) @@ -138,7 +133,6 @@ shared_examples_for Chef::Provider::File do before(:each) do allow(content).to receive(:tempfile).and_return(tempfile) allow(File).to receive(:exist?).with(tempfile.path).and_call_original - allow(File).to receive(:exists?).with(tempfile.path).and_call_original end after do @@ -547,7 +541,7 @@ shared_examples_for Chef::Provider::File do provider.load_current_resource tempfile = double("Tempfile", path: "/tmp/foo-bar-baz") allow(content).to receive(:tempfile).and_return(tempfile) - expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(true) + expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(true) expect(tempfile).to receive(:close).once expect(tempfile).to receive(:unlink).once end @@ -630,7 +624,7 @@ shared_examples_for Chef::Provider::File do it "raises an exception when the content object returns a tempfile that does not exist" do tempfile = double("Tempfile", path: "/tmp/foo-bar-baz") expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) - expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false) + expect(File).to receive(:exist?).with("/tmp/foo-bar-baz").and_return(false) expect { provider.send(:do_contents_changes) }.to raise_error(RuntimeError) end end diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb index 6e11235e30..4f6d619ccb 100644 --- a/spec/unit/provider/apt_update_spec.rb +++ b/spec/unit/provider/apt_update_spec.rb @@ -75,7 +75,9 @@ describe "Chef::Provider::AptUpdate" do describe "#action_periodic" do before do - allow(File).to receive(:exist?) + allow(File).to receive(:exist?).with(config_file).and_return(true) + allow(File).to receive(:exist?).with(config_dir).and_return(true) + allow(File).to receive(:exist?).with(stamp_dir).and_return(true) allow(File).to receive(:exist?).with(Dir.tmpdir).and_return(true) expect(File).to receive(:exist?).with("#{stamp_dir}/update-success-stamp").and_return(true) end |