summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-11-21 21:34:19 -0800
committerTim Smith <tsmith84@gmail.com>2020-11-27 15:04:01 -0800
commit6b2f219f13b7d28ee9277f98bf11e69903fefc92 (patch)
treece287b5e1e9674c6a2db05ecd712c2493cb6a450 /spec
parent8bd0da60b8b5867566b4a2fbf339c7c97eb8bd6a (diff)
downloadchef-exists.tar.gz
Convert the last our of File.exists? to File.exist?exists
Standardize on the new method Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/execute_spec.rb2
-rw-r--r--spec/support/shared/unit/provider/file.rb10
-rw-r--r--spec/unit/client_spec.rb4
-rw-r--r--spec/unit/dsl/reboot_pending_spec.rb4
-rw-r--r--spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb4
-rw-r--r--spec/unit/provider/launchd_spec.rb4
-rw-r--r--spec/unit/provider/link_spec.rb14
-rw-r--r--spec/unit/provider/mount/aix_spec.rb4
-rw-r--r--spec/unit/provider/mount/linux_spec.rb9
-rw-r--r--spec/unit/provider/mount/mount_spec.rb12
-rw-r--r--spec/unit/provider/package/rpm_spec.rb2
-rw-r--r--spec/unit/provider/template_spec.rb4
12 files changed, 34 insertions, 39 deletions
diff --git a/spec/functional/resource/execute_spec.rb b/spec/functional/resource/execute_spec.rb
index 3d7e185e17..c05d8da3ef 100644
--- a/spec/functional/resource/execute_spec.rb
+++ b/spec/functional/resource/execute_spec.rb
@@ -62,7 +62,7 @@ describe Chef::Resource::Execute do
end
describe "when parent resource sets :cwd" do
- let(:guard) { %{ruby -e 'exit 1 unless File.exists?("./nested.json")'} }
+ let(:guard) { %{ruby -e 'exit 1 unless File.exist?("./nested.json")'} }
it "guard inherits :cwd from resource and runs" do
resource.cwd CHEF_SPEC_DATA
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index f624a6ae44..dbbb4583d0 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
@@ -533,7 +527,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
@@ -616,7 +610,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/client_spec.rb b/spec/unit/client_spec.rb
index 377a0b8f05..c19a32cecd 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -113,8 +113,8 @@ shared_context "a client run" do
# --Client.register
# Make sure Client#register thinks the client key doesn't
# exist, so it tries to register and create one.
- allow(File).to receive(:exists?).and_call_original
- expect(File).to receive(:exists?)
+ allow(File).to receive(:exist?).and_call_original
+ expect(File).to receive(:exist?)
.with(Chef::Config[:client_key])
.exactly(:once)
.and_return(api_client_exists?)
diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb
index 4fed3be442..3ad1be9e38 100644
--- a/spec/unit/dsl/reboot_pending_spec.rb
+++ b/spec/unit/dsl/reboot_pending_spec.rb
@@ -57,12 +57,12 @@ describe Chef::DSL::RebootPending do
end
it "should return true if /var/run/reboot-required exists" do
- allow(File).to receive(:exists?).with("/var/run/reboot-required").and_return(true)
+ allow(File).to receive(:exist?).with("/var/run/reboot-required").and_return(true)
expect(recipe.reboot_pending?).to be_truthy
end
it "should return false if /var/run/reboot-required does not exist" do
- allow(File).to receive(:exists?).with("/var/run/reboot-required").and_return(false)
+ allow(File).to receive(:exist?).with("/var/run/reboot-required").and_return(false)
expect(recipe.reboot_pending?).to be_falsey
end
end
diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
index 9d8fb050da..6693eded03 100644
--- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
+++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
@@ -115,7 +115,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do
# fake code to run through #recipe_snippet
source_file = [ "if true", "var = non_existent", "end" ]
allow(IO).to receive(:readlines).and_return(source_file)
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
end
it "parses a Windows path" do
@@ -141,7 +141,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do
context "when the recipe file does not exist" do
before do
- allow(File).to receive(:exists?).and_return(false)
+ allow(File).to receive(:exist?).and_return(false)
allow(IO).to receive(:readlines).and_raise(Errno::ENOENT)
end
diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb
index 6a729c2cb6..b3306d2676 100644
--- a/spec/unit/provider/launchd_spec.rb
+++ b/spec/unit/provider/launchd_spec.rb
@@ -197,7 +197,7 @@ describe Chef::Provider::Launchd do
describe "with an :delete action" do
describe "and the ld file is present" do
before(:each) do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
allow(provider).to receive(
:manage_service
).with(:disable).and_return(true)
@@ -218,7 +218,7 @@ describe Chef::Provider::Launchd do
describe "and the ld file is not present" do
before(:each) do
- allow(File).to receive(:exists?).and_return(false)
+ allow(File).to receive(:exist?).and_return(false)
allow(provider).to receive(
:manage_plist
).with(:delete).and_return(true)
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index eebf0a9d07..b56d67ae77 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -125,7 +125,7 @@ describe Chef::Resource::Link do
describe "when the target doesn't exist" do
before do
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
provider.load_current_resource
end
@@ -152,13 +152,13 @@ describe Chef::Resource::Link do
allow(stat).to receive(:mode).and_return(0755)
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat)
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
end
describe "and the source does not exist" do
before do
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false)
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false)
provider.load_current_resource
end
@@ -185,7 +185,7 @@ describe Chef::Resource::Link do
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
provider.load_current_resource
end
@@ -212,7 +212,7 @@ describe Chef::Resource::Link do
allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat)
- allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
+ allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true)
provider.load_current_resource
end
@@ -336,10 +336,10 @@ describe Chef::Resource::Link do
"#{CHEF_SPEC_DATA}/fofile-link"
).and_return(false)
- allow(File).to receive(:exists?).with(
+ allow(File).to receive(:exist?).with(
"#{CHEF_SPEC_DATA}/fofile-link"
).and_return(true)
- allow(File).to receive(:exists?).with(
+ allow(File).to receive(:exist?).with(
"#{CHEF_SPEC_DATA}/fofile"
).and_return(true)
diff --git a/spec/unit/provider/mount/aix_spec.rb b/spec/unit/provider/mount/aix_spec.rb
index 3d77a23bd6..de00528b68 100644
--- a/spec/unit/provider/mount/aix_spec.rb
+++ b/spec/unit/provider/mount/aix_spec.rb
@@ -65,8 +65,8 @@ describe Chef::Provider::Mount::Aix do
@provider = Chef::Provider::Mount::Aix.new(@new_resource, @run_context)
- allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true
- allow(::File).to receive(:exists?).with("/tmp/foo").and_return true
+ allow(::File).to receive(:exist?).with("/dev/sdz1").and_return true
+ allow(::File).to receive(:exist?).with("/tmp/foo").and_return true
end
def stub_mounted(provider, mounted_output)
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb
index 3e41f895d1..4f25367c53 100644
--- a/spec/unit/provider/mount/linux_spec.rb
+++ b/spec/unit/provider/mount/linux_spec.rb
@@ -5,7 +5,7 @@ describe Chef::Provider::Mount::Linux do
let(:run_context) do
node = Chef::Node.new
events = Chef::EventDispatch::Dispatcher.new
- run_context = Chef::RunContext.new(node, {}, events)
+ Chef::RunContext.new(node, {}, events)
end
let(:new_resource) do
@@ -22,9 +22,10 @@ describe Chef::Provider::Mount::Linux do
end
before(:each) do
- allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true
- allow(::File).to receive(:exists?).with("/tmp/foo").and_return true
- allow(::File).to receive(:exists?).with("//192.168.11.102/Share/backup").and_return true
+ allow(::File).to receive(:exist?).with("/etc/fstab").and_return false
+ allow(::File).to receive(:exist?).with("/dev/sdz1").and_return true
+ allow(::File).to receive(:exist?).with("/tmp/foo").and_return true
+ allow(::File).to receive(:exist?).with("//192.168.11.102/Share/backup").and_return true
allow(::File).to receive(:realpath).with("/dev/sdz1").and_return "/dev/sdz1"
allow(::File).to receive(:realpath).with("/tmp/foo").and_return "/tmp/foo"
end
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index 9a7d9198b5..1985b52ca0 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -34,8 +34,8 @@ describe Chef::Provider::Mount::Mount do
@provider = Chef::Provider::Mount::Mount.new(@new_resource, @run_context)
- allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true
- allow(::File).to receive(:exists?).with("/tmp/foo").and_return true
+ allow(::File).to receive(:exist?).with("/dev/sdz1").and_return true
+ allow(::File).to receive(:exist?).with("/tmp/foo").and_return true
allow(::File).to receive(:realpath).with("/dev/sdz1").and_return "/dev/sdz1"
allow(::File).to receive(:realpath).with("/tmp/foo").and_return "/tmp/foo"
end
@@ -82,12 +82,12 @@ describe Chef::Provider::Mount::Mount do
end
it "should raise an error if the mount device does not exist" do
- allow(::File).to receive(:exists?).with("/dev/sdz1").and_return false
+ allow(::File).to receive(:exist?).with("/dev/sdz1").and_return false
expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount)
end
it "should not call mountable? with load_current_resource - CHEF-1565" do
- allow(::File).to receive(:exists?).with("/dev/sdz1").and_return false
+ allow(::File).to receive(:exist?).with("/dev/sdz1").and_return false
expect(@provider).to receive(:mounted?).and_return(true)
expect(@provider).to receive(:enabled?).and_return(true)
expect(@provider).not_to receive(:mountable?)
@@ -99,12 +99,12 @@ describe Chef::Provider::Mount::Mount do
@new_resource.device_type :uuid
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
expect(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status)
- expect(::File).to receive(:exists?).with("").and_return(false)
+ expect(::File).to receive(:exist?).with("").and_return(false)
expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount)
end
it "should raise an error if the mount point does not exist" do
- allow(::File).to receive(:exists?).with("/tmp/foo").and_return false
+ allow(::File).to receive(:exist?).with("/tmp/foo").and_return false
expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount)
end
diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb
index edf39b0f3f..d42e3061bc 100644
--- a/spec/unit/provider/package/rpm_spec.rb
+++ b/spec/unit/provider/package/rpm_spec.rb
@@ -41,7 +41,7 @@ describe Chef::Provider::Package::Rpm do
let(:rpm_q_status) { instance_double("Mixlib::ShellOut", exitstatus: rpm_q_exitstatus, stdout: rpm_q_stdout) }
before(:each) do
- allow(::File).to receive(:exist?).with("PLEASE STUB File.exists? EXACTLY").and_return(true)
+ allow(::File).to receive(:exist?).with("PLEASE STUB File.exist? EXACTLY").and_return(true)
# Ensure all shell out usage is stubbed with exact arguments
allow(provider).to receive(:shell_out_compacted!).with("PLEASE STUB YOUR SHELLOUT CALLS").and_return(nil)
diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb
index 84cbfc5d08..e6e251bc22 100644
--- a/spec/unit/provider/template_spec.rb
+++ b/spec/unit/provider/template_spec.rb
@@ -50,7 +50,7 @@ describe Chef::Provider::Template do
let(:content) do
content = double("Chef::Provider::File::Content::Template", template_location: "/foo/bar/baz")
- allow(File).to receive(:exists?).with("/foo/bar/baz").and_return(true)
+ allow(File).to receive(:exist?).with("/foo/bar/baz").and_return(true)
content
end
@@ -76,7 +76,7 @@ describe Chef::Provider::Template do
it "stops executing when the local template source can't be found" do
setup_normal_file
allow(content).to receive(:template_location).and_return("/baz/bar/foo")
- allow(File).to receive(:exists?).with("/baz/bar/foo").and_return(false)
+ allow(File).to receive(:exist?).with("/baz/bar/foo").and_return(false)
expect { provider.run_action(:create) }.to raise_error Chef::Mixin::WhyRun::ResourceRequirements::Assertion::AssertionFailure
end