diff options
Diffstat (limited to 'spec')
23 files changed, 324 insertions, 310 deletions
diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index dba56b186d..3e3853af28 100644 --- a/spec/unit/provider/package/aix_spec.rb +++ b/spec/unit/provider/package/aix_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::Package::Aix do @new_resource.source("/tmp/samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) - allow(::File).to receive(:exists?).with(@new_resource.source).and_return(true) + allow(::File).to receive(:exist?).with(@new_resource.source).and_return(true) end describe "assessing the current package status" do @@ -41,23 +41,23 @@ describe Chef::Provider::Package::Aix do it "should create a current resource with the name of new_resource" do status = double("Status", :stdout => @bffinfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(@empty_status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) @provider.load_current_resource expect(@provider.current_resource.name).to eq("samba.base") end it "should set the current resource bff package name to the new resource bff package name" do status = double("Status", :stdout => @bffinfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(@empty_status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") end it "should raise an exception if a source is supplied but not found" do allow(@provider).to receive(:shell_out).and_return(@empty_status) - allow(::File).to receive(:exists?).with(@new_resource.source).and_return(false) + allow(::File).to receive(:exist?).with(@new_resource.source).and_return(false) @provider.load_current_resource @provider.define_resource_requirements expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package) @@ -65,8 +65,8 @@ describe Chef::Provider::Package::Aix do it "should get the source package version from lslpp if provided" do status = double("Status", :stdout => @bffinfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(@empty_status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") @@ -77,8 +77,8 @@ describe Chef::Provider::Package::Aix do info = "samba.base:samba.base.samples:3.3.12.0::COMMITTED:I:Samba for AIX: /etc/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX:" status = double("Status", :stdout => info, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(@empty_status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) expect(Chef::Log).to receive(:warn).once.with(%r{bff package by product name}) @provider.load_current_resource @@ -90,8 +90,8 @@ describe Chef::Provider::Package::Aix do status = double("Status", :stdout => @bffinfo, :exitstatus => 0) @stdout = StringIO.new(@bffinfo) @stdin, @stderr = StringIO.new, StringIO.new - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to eq("3.3.12.0") end @@ -112,8 +112,8 @@ describe Chef::Provider::Package::Aix do it "should return a current resource with a nil version if the package is not found" do status = double("Status", :stdout => @bffinfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) - expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base", timeout: 900).and_return(@empty_status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) @provider.load_current_resource expect(@provider.current_resource.version).to be_nil end @@ -122,7 +122,7 @@ describe Chef::Provider::Package::Aix do wrongbffinfo = "/usr/lib/objrepos:openssl.base:0.9.8.2400::COMMITTED:I:Open Secure Socket Layer: /etc/objrepos:openssl.base:0.9.8.2400::COMMITTED:I:Open Secure Socket Layer:" status = double("Status", :stdout => wrongbffinfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base", timeout: 900).and_return(status) + expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end end @@ -130,7 +130,7 @@ describe Chef::Provider::Package::Aix do describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "3.3.12.0" - expect(@provider).not_to receive(:shell_out ) + expect(@provider).not_to receive(:shell_out) @provider.candidate_version end @@ -150,7 +150,7 @@ describe Chef::Provider::Package::Aix do describe "install and upgrade" do it "should run installp -aYF -d with the package source to install" do - expect(@provider).to receive(:shell_out!).with("installp -aYF -d /tmp/samba.base samba.base", timeout: 900) + expect(@provider).to receive(:shell_out!).with("installp", "-aYF", "-d", "/tmp/samba.base", "samba.base", timeout: 900) @provider.install_package("samba.base", "3.3.12.0") end @@ -158,26 +158,26 @@ describe Chef::Provider::Package::Aix do @new_resource = Chef::Resource::Package.new("/tmp/samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) expect(@new_resource.source).to eq("/tmp/samba.base") - expect(@provider).to receive(:shell_out!).with("installp -aYF -d /tmp/samba.base /tmp/samba.base", timeout: 900) + expect(@provider).to receive(:shell_out!).with("installp", "-aYF", "-d", "/tmp/samba.base", "/tmp/samba.base", timeout: 900) @provider.install_package("/tmp/samba.base", "3.3.12.0") end it "should run installp with -eLogfile option." do allow(@new_resource).to receive(:options).and_return("-e/tmp/installp.log") - expect(@provider).to receive(:shell_out!).with("installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base", timeout: 900) + expect(@provider).to receive(:shell_out!).with("installp", "-aYF", "-e/tmp/installp.log", "-d", "/tmp/samba.base", "samba.base", timeout: 900) @provider.install_package("samba.base", "3.3.12.0") end end describe "remove" do it "should run installp -u samba.base to remove the package" do - expect(@provider).to receive(:shell_out!).with("installp -u samba.base", timeout: 900) + expect(@provider).to receive(:shell_out!).with("installp", "-u", "samba.base", timeout: 900) @provider.remove_package("samba.base", "3.3.12.0") end it "should run installp -u -e/tmp/installp.log with options -e/tmp/installp.log" do allow(@new_resource).to receive(:options).and_return("-e/tmp/installp.log") - expect(@provider).to receive(:shell_out!).with("installp -u -e/tmp/installp.log samba.base", timeout: 900) + expect(@provider).to receive(:shell_out!).with("installp", "-u", "-e/tmp/installp.log", "samba.base", timeout: 900) @provider.remove_package("samba.base", "3.3.12.0") end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index cf31c3d7cc..e14af488ac 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,7 +51,7 @@ irssi: it "should create a current resource with the name of the new_resource" do expect(@provider).to receive(:shell_out!).with( - "apt-cache policy #{@new_resource.package_name}", + "apt-cache", "policy", @new_resource.package_name, :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(@shell_out) @@ -91,7 +91,7 @@ N: Unable to locate package conic-smarms POLICY_STDOUT policy = double(:stdout => policy_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache policy conic-smarms", + "apt-cache", "policy", "conic-smarms", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(policy) @@ -100,7 +100,7 @@ N: Unable to locate package conic-smarms SHOWPKG_STDOUT showpkg = double(:stdout => showpkg_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache showpkg conic-smarms", + "apt-cache", "showpkg", "conic-smarms", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(showpkg) @@ -119,7 +119,7 @@ libmysqlclient15-dev: VPKG_STDOUT virtual_package = double(:stdout => virtual_package_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache policy libmysqlclient15-dev", + "apt-cache", "policy", "libmysqlclient15-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(virtual_package) @@ -143,7 +143,7 @@ libmysqlclient-dev 5.1.41-3ubuntu12 SHOWPKG_STDOUT showpkg = double(:stdout => showpkg_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache showpkg libmysqlclient15-dev", + "apt-cache", "showpkg", "libmysqlclient15-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(showpkg) @@ -162,7 +162,7 @@ libmysqlclient-dev: RPKG_STDOUT real_package = double(:stdout => real_package_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache policy libmysqlclient-dev", + "apt-cache", "policy", "libmysqlclient-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(real_package) @@ -179,7 +179,7 @@ mp3-decoder: VPKG_STDOUT virtual_package = double(:stdout => virtual_package_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache policy mp3-decoder", + "apt-cache", "policy", "mp3-decoder", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(virtual_package) @@ -206,7 +206,7 @@ mpg123 1.12.1-0ubuntu1 SHOWPKG_STDOUT showpkg = double(:stdout => showpkg_out, :exitstatus => 0) expect(@provider).to receive(:shell_out!).with( - "apt-cache showpkg mp3-decoder", + "apt-cache", "showpkg", "mp3-decoder", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(showpkg) @@ -220,7 +220,7 @@ mpg123 1.12.1-0ubuntu1 allow(@new_resource).to receive(:default_release).and_return("lenny-backports") allow(@new_resource).to receive(:provider).and_return(nil) expect(@provider).to receive(:shell_out!).with( - "apt-cache -o APT::Default-Release=lenny-backports policy irssi", + "apt-cache", "-o", "APT::Default-Release=lenny-backports", "policy", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ).and_return(@shell_out) @@ -230,7 +230,7 @@ mpg123 1.12.1-0ubuntu1 it "raises an exception if a source is specified (CHEF-5113)" do @new_resource.source "pluto" expect(@provider).to receive(:shell_out!).with( - "apt-cache policy #{@new_resource.package_name}", + "apt-cache", "policy", @new_resource.package_name, :env => { "DEBIAN_FRONTEND" => "noninteractive" } , :timeout => @timeout ).and_return(@shell_out) @@ -259,7 +259,7 @@ mpg123 1.12.1-0ubuntu1 describe "install_package" do it "should run apt-get install with the package name and version" do expect(@provider).to receive(:shell_out!). with( - "apt-get -q -y install irssi=0.8.12-7", + "apt-get", "-q", "-y", "install", "irssi=0.8.12-7", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -268,7 +268,7 @@ mpg123 1.12.1-0ubuntu1 it "should run apt-get install with the package name and version and options if specified" do expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y --force-yes install irssi=0.8.12-7", + "apt-get", "-q", "-y", "--force-yes", "install", "irssi=0.8.12-7", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -284,7 +284,7 @@ mpg123 1.12.1-0ubuntu1 @provider.new_resource = @new_resource expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7", + "apt-get", "-q", "-y", "-o", "APT::Default-Release=lenny-backports", "install", "irssi=0.8.12-7", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -305,7 +305,7 @@ mpg123 1.12.1-0ubuntu1 it "should run apt-get remove with the package name" do expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y remove irssi", + "apt-get", "-q", "-y", "remove", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -314,7 +314,7 @@ mpg123 1.12.1-0ubuntu1 it "should run apt-get remove with the package name and options if specified" do expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y --force-yes remove irssi", + "apt-get", "-q", "-y", "--force-yes", "remove", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -328,7 +328,7 @@ mpg123 1.12.1-0ubuntu1 it "should run apt-get purge with the package name" do expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y purge irssi", + "apt-get", "-q", "-y", "purge", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -337,7 +337,7 @@ mpg123 1.12.1-0ubuntu1 it "should run apt-get purge with the package name and options if specified" do expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y --force-yes purge irssi", + "apt-get", "-q", "-y", "--force-yes", "purge", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -356,7 +356,7 @@ mpg123 1.12.1-0ubuntu1 file = "/tmp/irssi-0.8.12-7.seed" expect(@provider).to receive(:shell_out!).with( - "debconf-set-selections /tmp/irssi-0.8.12-7.seed", + "debconf-set-selections", "/tmp/irssi-0.8.12-7.seed", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -366,7 +366,7 @@ mpg123 1.12.1-0ubuntu1 it "should run debconf-set-selections on the preseed file if it has changed" do expect(@provider).to receive(:shell_out!).with( - "debconf-set-selections /tmp/irssi-0.8.12-7.seed", + "debconf-set-selections", "/tmp/irssi-0.8.12-7.seed", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -387,7 +387,7 @@ mpg123 1.12.1-0ubuntu1 describe "when reconfiguring a package" do it "should run dpkg-reconfigure package" do expect(@provider).to receive(:shell_out!).with( - "dpkg-reconfigure irssi", + "dpkg-reconfigure", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -398,7 +398,7 @@ mpg123 1.12.1-0ubuntu1 describe "when locking a package" do it "should run apt-mark hold package" do expect(@provider).to receive(:shell_out!).with( - "apt-mark hold irssi", + "apt-mark", "hold", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -409,7 +409,7 @@ mpg123 1.12.1-0ubuntu1 describe "when unlocking a package" do it "should run apt-mark unhold package" do expect(@provider).to receive(:shell_out!).with( - "apt-mark unhold irssi", + "apt-mark", "unhold", "irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -421,7 +421,7 @@ mpg123 1.12.1-0ubuntu1 it "should install the package without specifying a version" do @provider.package_data["libmysqlclient15-dev"][:virtual] = true expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y install libmysqlclient15-dev", + "apt-get", "-q", "-y", "install", "libmysqlclient15-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -433,7 +433,7 @@ mpg123 1.12.1-0ubuntu1 it "should remove the resolved name instead of the virtual package name" do expect(@provider).to receive(:resolve_virtual_package_name).with("libmysqlclient15-dev").and_return("libmysqlclient-dev") expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y remove libmysqlclient-dev", + "apt-get", "-q", "-y", "remove", "libmysqlclient-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -445,7 +445,7 @@ mpg123 1.12.1-0ubuntu1 it "should purge the resolved name instead of the virtual package name" do expect(@provider).to receive(:resolve_virtual_package_name).with("libmysqlclient15-dev").and_return("libmysqlclient-dev") expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y purge libmysqlclient-dev", + "apt-get", "-q", "-y", "purge", "libmysqlclient-dev", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) @@ -457,7 +457,7 @@ mpg123 1.12.1-0ubuntu1 it "can install a virtual package followed by a non-virtual package" do # https://github.com/chef/chef/issues/2914 expect(@provider).to receive(:shell_out!).with( - "apt-get -q -y install libmysqlclient15-dev irssi=0.8.12-7", + "apt-get", "-q", "-y", "install", "libmysqlclient15-dev", "irssi=0.8.12-7", :env => { "DEBIAN_FRONTEND" => "noninteractive" }, :timeout => @timeout ) diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 613f7a326e..e01e1d9cce 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -51,8 +51,8 @@ Conflicts: wget-ssl end before(:each) do - allow(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(dpkg_deb_status) - allow(provider).to receive(:shell_out!).with("dpkg -s #{package}", timeout: 900, returns: [0, 1]).and_return(double(stdout: "", exitstatus: 1)) + allow(provider).to receive(:shell_out!).with("dpkg-deb", "-W", source, timeout: 900).and_return(dpkg_deb_status) + allow(provider).to receive(:shell_out!).with("dpkg", "-s", package, timeout: 900, returns: [0, 1]).and_return(double(stdout: "", exitstatus: 1)) allow(::File).to receive(:exist?).with(source).and_return(true) end @@ -113,7 +113,7 @@ Conflicts: wget-ssl describe "gets the source package version from dpkg-deb" do def check_version(version) status = double(:stdout => "wget\t#{version}", :exitstatus => 0) - expect(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(status) + expect(provider).to receive(:shell_out!).with("dpkg-deb", "-W", source, timeout: 900).and_return(status) provider.load_current_resource expect(provider.current_resource.package_name).to eq(["wget"]) expect(provider.candidate_version).to eq([version]) @@ -165,7 +165,7 @@ Conflicts: wget-ssl end it "should return the current version installed if found by dpkg" do - allow(provider).to receive(:shell_out!).with("dpkg -s #{package}", timeout: 900, returns: [0, 1]).and_return(dpkg_s_status) + allow(provider).to receive(:shell_out!).with("dpkg", "-s", package, timeout: 900, returns: [0, 1]).and_return(dpkg_s_status) provider.load_current_resource expect(provider.current_resource.version).to eq(["1.11.4-1ubuntu1"]) end @@ -178,7 +178,7 @@ Use dpkg --info (= dpkg-deb --info) to examine archive files, and dpkg --contents (= dpkg-deb --contents) to list their contents. EOF ) - expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_return(dpkg_s_status) + expect(provider).to receive(:shell_out!).with("dpkg", "-s", package, returns: [0, 1], timeout: 900).and_return(dpkg_s_status) provider.load_current_resource expect(provider.current_resource.version).to eq([nil]) end @@ -192,7 +192,7 @@ Priority: extra Section: ruby EOF ) - expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_return(dpkg_s_status) + expect(provider).to receive(:shell_out!).with("dpkg", "-s", package, returns: [0, 1], timeout: 900).and_return(dpkg_s_status) provider.load_current_resource expect(provider.current_resource.version).to eq([nil]) end @@ -201,13 +201,13 @@ Section: ruby dpkg_s_status = double( exitstatus: 3, stderr: "i am very, very angry with you. i'm very, very cross. go to your room.", stdout: "" ) - expect(provider).to receive(:shell_out!).with("dpkg -s #{package}", returns: [0, 1], timeout: 900).and_raise(Mixlib::ShellOut::ShellCommandFailed) + expect(provider).to receive(:shell_out!).with("dpkg", "-s", package, returns: [0, 1], timeout: 900).and_raise(Mixlib::ShellOut::ShellCommandFailed) expect { provider.load_current_resource }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end it "should raise an exception if dpkg-deb -W fails to run" do status = double(:stdout => "", :exitstatus => -1) - expect(provider).to receive(:shell_out_with_timeout!).with("dpkg-deb -W /tmp/wget_1.11.4-1ubuntu1_amd64.deb").and_raise(Mixlib::ShellOut::ShellCommandFailed) + expect(provider).to receive(:shell_out_compact_timeout!).with("dpkg-deb", "-W", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb").and_raise(Mixlib::ShellOut::ShellCommandFailed) expect { provider.load_current_resource }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end end @@ -215,7 +215,7 @@ Section: ruby describe Chef::Provider::Package::Dpkg, "install and upgrade" do it "should run dpkg -i with the package source" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg", "-i", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) provider.load_current_resource provider.run_action(:install) @@ -224,7 +224,7 @@ Section: ruby it "should run dpkg -i if the package is a path and the source is nil" do new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg", "-i", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) provider.run_action(:install) end @@ -232,7 +232,7 @@ Section: ruby it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg", "-i", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) provider.run_action(:upgrade) end @@ -240,7 +240,7 @@ Section: ruby it "should run dpkg -i with the package source and options if specified" do new_resource.options "--force-yes" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i", "--force-yes", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg", "-i", "--force-yes", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) provider.run_action(:install) end @@ -254,14 +254,14 @@ Section: ruby describe Chef::Provider::Package::Dpkg, "remove and purge" do it "should run dpkg -r to remove the package" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -r", nil, "wget" + "dpkg", "-r", "wget" ) provider.remove_package(["wget"], ["1.11.4-1ubuntu1"]) end it "should run dpkg -r to remove the package with options if specified" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -r", "--force-yes", "wget" + "dpkg", "-r", "--force-yes", "wget" ) allow(new_resource).to receive(:options).and_return("--force-yes") @@ -270,14 +270,14 @@ Section: ruby it "should run dpkg -P to purge the package" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -P", nil, "wget" + "dpkg", "-P", "wget" ) provider.purge_package(["wget"], ["1.11.4-1ubuntu1"]) end it "should run dpkg -P to purge the package with options if specified" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -P", "--force-yes", "wget" + "dpkg", "-P", "--force-yes", "wget" ) allow(new_resource).to receive(:options).and_return("--force-yes") diff --git a/spec/unit/provider/package/easy_install_spec.rb b/spec/unit/provider/package/easy_install_spec.rb index 51d95c6968..910f01bfeb 100644 --- a/spec/unit/provider/package/easy_install_spec.rb +++ b/spec/unit/provider/package/easy_install_spec.rb @@ -62,51 +62,51 @@ describe Chef::Provider::Package::EasyInstall do describe "actions_on_package" do it "should run easy_install with the package name and version" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install \"boto==1.8d\"", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "boto==1.8d", { timeout: 900 } + ) @provider.install_package("boto", "1.8d") end it "should run easy_install with the package name and version and specified options" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install --always-unzip \"boto==1.8d\"", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "--always-unzip", "boto==1.8d", { timeout: 900 } + ) allow(@new_resource).to receive(:options).and_return("--always-unzip") @provider.install_package("boto", "1.8d") end it "should run easy_install with the package name and version" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install \"boto==1.8d\"", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "boto==1.8d", { timeout: 900 } + ) @provider.upgrade_package("boto", "1.8d") end it "should run easy_install -m with the package name and version" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install -m boto", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "-m", "boto", { timeout: 900 } + ) @provider.remove_package("boto", "1.8d") end it "should run easy_install -m with the package name and version and specified options" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install -x -m boto", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "-x", "-m", "boto", { timeout: 900 } + ) allow(@new_resource).to receive(:options).and_return("-x") @provider.remove_package("boto", "1.8d") end it "should run easy_install -m with the package name and version" do expect(Chef).to receive(:deprecated).with(:easy_install, /easy_install package provider is deprecated/) - expect(@provider).to receive(:run_command).with({ - :command => "easy_install -m boto", - }) + expect(@provider).to receive(:shell_out!).with( + "easy_install", "-m", "boto", { timeout: 900 } + ) @provider.purge_package("boto", "1.8d") end diff --git a/spec/unit/provider/package/freebsd/pkg_spec.rb b/spec/unit/provider/package/freebsd/pkg_spec.rb index 8890f62f73..4b3a94aa33 100644 --- a/spec/unit/provider/package/freebsd/pkg_spec.rb +++ b/spec/unit/provider/package/freebsd/pkg_spec.rb @@ -31,6 +31,8 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do @provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context) @provider.current_resource = @current_resource allow(::File).to receive(:exist?).with("/usr/ports/Makefile").and_return(false) + allow(::File).to receive(:exist?).with("/usr/ports/www/wordpress").and_return(false) + allow(::File).to receive(:exist?).with("www/wordpress").and_return(false) end describe "when determining the current package state" do @@ -77,23 +79,21 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should return the version number when it is installed" do pkg_info = OpenStruct.new(:stdout => "zsh-4.3.6_7") - expect(@provider).to receive(:shell_out!).with('pkg_info -E "zsh*"', env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) - #@provider.should_receive(:popen4).with('pkg_info -E "zsh*"').and_yield(@pid, @stdin, ["zsh-4.3.6_7"], @stderr).and_return(@status) + expect(@provider).to receive(:shell_out!).with("pkg_info", "-E", "zsh*", env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) allow(@provider).to receive(:package_name).and_return("zsh") expect(@provider.current_installed_version).to eq("4.3.6_7") end it "does not set the current version number when the package is not installed" do pkg_info = OpenStruct.new(:stdout => "") - expect(@provider).to receive(:shell_out!).with('pkg_info -E "zsh*"', env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) + expect(@provider).to receive(:shell_out!).with("pkg_info", "-E", "zsh*", env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) allow(@provider).to receive(:package_name).and_return("zsh") expect(@provider.current_installed_version).to be_nil end it "should return the port path for a valid port name" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out!).with("whereis -s zsh", env: nil, timeout: 900).and_return(whereis) - #@provider.should_receive(:popen4).with("whereis -s zsh").and_yield(@pid, @stdin, ["zsh: /usr/ports/shells/zsh"], @stderr).and_return(@status) + expect(@provider).to receive(:shell_out!).with("whereis", "-s", "zsh", env: nil, timeout: 900).and_return(whereis) allow(@provider).to receive(:port_name).and_return("zsh") expect(@provider.port_path).to eq("/usr/ports/shells/zsh") end @@ -102,7 +102,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should return the ports candidate version when given a valid port path" do allow(@provider).to receive(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "4.3.6\n", :exitstatus => 0) - expect(@provider).to receive(:shell_out!).with("make -V PORTVERSION", { cwd: "/usr/ports/shells/zsh", returns: [0, 1], env: nil, timeout: 900 }).and_return(make_v) + expect(@provider).to receive(:shell_out!).with("make", "-V", "PORTVERSION", { cwd: "/usr/ports/shells/zsh", returns: [0, 1], env: nil, timeout: 900 }).and_return(make_v) expect(@provider.ports_candidate_version).to eq("4.3.6") end @@ -110,7 +110,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do allow(::File).to receive(:exist?).with("/usr/ports/Makefile").and_return(true) allow(@provider).to receive(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "zsh-4.3.6_7\n", :exitstatus => 0) - expect(@provider).to receive(:shell_out!).with("make -V PKGNAME", { cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900 }).and_return(make_v) + expect(@provider).to receive(:shell_out!).with("make", "-V", "PKGNAME", { cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900 }).and_return(make_v) #@provider.should_receive(:ports_makefile_variable_value).with("PKGNAME").and_return("zsh-4.3.6_7") expect(@provider.package_name).to eq("zsh") end @@ -127,7 +127,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do end it "should run pkg_add -r with the package name" do - expect(@provider).to receive(:shell_out!).with("pkg_add -r zsh", env: nil, timeout: 900).and_return(@cmd_result) + expect(@provider).to receive(:shell_out!).with("pkg_add", "-r", "zsh", env: nil, timeout: 900).and_return(@cmd_result) @provider.install_package("zsh", "4.3.6_7") end end @@ -142,7 +142,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should figure out the port path from the package_name using whereis" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out!).with("whereis -s zsh", env: nil, timeout: 900).and_return(whereis) + expect(@provider).to receive(:shell_out!).with("whereis", "-s", "zsh", env: nil, timeout: 900).and_return(whereis) expect(@provider.port_path).to eq("/usr/ports/shells/zsh") end @@ -178,7 +178,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do end it "should run pkg_add -r with the package name" do - expect(@provider).to receive(:shell_out!).with("pkg_add -r ruby18-iconv", env: nil, timeout: 900).and_return(@install_result) + expect(@provider).to receive(:shell_out!).with("pkg_add", "-r", "ruby18-iconv", env: nil, timeout: 900).and_return(@install_result) @provider.install_package("ruby-iconv", "1.0") end end @@ -193,7 +193,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do end it "should run pkg_delete with the package name and version" do - expect(@provider).to receive(:shell_out!).with("pkg_delete zsh-4.3.6_7", env: nil, timeout: 900).and_return(@pkg_delete) + expect(@provider).to receive(:shell_out!).with("pkg_delete", "zsh-4.3.6_7", env: nil, timeout: 900).and_return(@pkg_delete) @provider.remove_package("zsh", "4.3.6_7") end end @@ -213,14 +213,14 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should return the port path for a valid port name" do whereis = OpenStruct.new(:stdout => "bonnie++: /usr/ports/benchmarks/bonnie++") - expect(@provider).to receive(:shell_out!).with("whereis -s bonnie++", env: nil, timeout: 900).and_return(whereis) + expect(@provider).to receive(:shell_out!).with("whereis", "-s", "bonnie++", env: nil, timeout: 900).and_return(whereis) allow(@provider).to receive(:port_name).and_return("bonnie++") expect(@provider.port_path).to eq("/usr/ports/benchmarks/bonnie++") end it "should return the version number when it is installed" do pkg_info = OpenStruct.new(:stdout => "bonnie++-1.96") - expect(@provider).to receive(:shell_out!).with('pkg_info -E "bonnie++*"', env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) + expect(@provider).to receive(:shell_out!).with("pkg_info", "-E", "bonnie++*", env: nil, returns: [0, 1], timeout: 900).and_return(pkg_info) allow(@provider).to receive(:package_name).and_return("bonnie++") expect(@provider.current_installed_version).to eq("1.96") end @@ -253,7 +253,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do allow(@provider).to receive(:latest_link_name).and_return("perl") cmd = OpenStruct.new(:status => true) - expect(@provider).to receive(:shell_out!).with("pkg_add -r perl", env: nil, timeout: 900).and_return(cmd) + expect(@provider).to receive(:shell_out!).with("pkg_add", "-r", "perl", env: nil, timeout: 900).and_return(cmd) @provider.install_package("perl5.8", "5.8.8_1") end @@ -267,7 +267,7 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do allow(@provider).to receive(:latest_link_name).and_return("mysql50-server") cmd = OpenStruct.new(:status => true) - expect(@provider).to receive(:shell_out!).with("pkg_add -r mysql50-server", env: nil, timeout: 900).and_return(cmd) + expect(@provider).to receive(:shell_out!).with("pkg_add", "-r", "mysql50-server", env: nil, timeout: 900).and_return(cmd) @provider.install_package("mysql50-server", "5.0.45_1") end end diff --git a/spec/unit/provider/package/freebsd/pkgng_spec.rb b/spec/unit/provider/package/freebsd/pkgng_spec.rb index a2bd833d9e..098052a057 100644 --- a/spec/unit/provider/package/freebsd/pkgng_spec.rb +++ b/spec/unit/provider/package/freebsd/pkgng_spec.rb @@ -67,7 +67,7 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should query pkg database" do - expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "zsh", env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) expect(@provider.current_installed_version).to eq("3.1.7") end end @@ -75,14 +75,14 @@ describe Chef::Provider::Package::Freebsd::Port do describe "determining candidate version" do it "should query repository" do pkg_query = OpenStruct.new(:stdout => "5.0.5\n", :exitstatus => 0) - expect(@provider).to receive(:shell_out!).with("pkg rquery '%v' zsh", env: nil, timeout: 900).and_return(pkg_query) + expect(@provider).to receive(:shell_out!).with("pkg", "rquery", "%v", "zsh", env: nil, timeout: 900).and_return(pkg_query) expect(@provider.candidate_version).to eq("5.0.5") end it "should query specified repository when given option" do @provider.new_resource.options("-r LocalMirror") # This requires LocalMirror repo configuration. pkg_query = OpenStruct.new(:stdout => "5.0.3\n", :exitstatus => 0) - expect(@provider).to receive(:shell_out!).with("pkg rquery -r LocalMirror '%v' zsh", env: nil, timeout: 900).and_return(pkg_query) + expect(@provider).to receive(:shell_out!).with("pkg", "rquery", "-r", "LocalMirror", "%v", "zsh", env: nil, timeout: 900).and_return(pkg_query) expect(@provider.candidate_version).to eq("5.0.3") end @@ -100,7 +100,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should handle package source from file" do @provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz") expect(@provider).to receive(:shell_out!). - with("pkg add /nas/pkg/repo/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). + with("pkg", "add", "/nas/pkg/repo/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). and_return(@install_result) @provider.install_package("zsh", "5.0.1") end @@ -108,21 +108,21 @@ describe Chef::Provider::Package::Freebsd::Port do it "should handle package source over ftp or http" do @provider.new_resource.source("http://repo.example.com/zsh-5.0.1.txz") expect(@provider).to receive(:shell_out!). - with("pkg add http://repo.example.com/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). + with("pkg", "add", "http://repo.example.com/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name" do expect(@provider).to receive(:shell_out!). - with("pkg install -y zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) + with("pkg", "install", "-y", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name with a specified repo" do @provider.new_resource.options("-r LocalMirror") # This requires LocalMirror repo configuration. expect(@provider).to receive(:shell_out!). - with("pkg install -y -r LocalMirror zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) + with("pkg", "install", "-y", "-r", "LocalMirror", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end end @@ -134,14 +134,14 @@ describe Chef::Provider::Package::Freebsd::Port do it "should call pkg delete" do expect(@provider).to receive(:shell_out!). - with("pkg delete -y zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) + with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end it "should not include repo option in pkg delete" do @provider.new_resource.options("-r LocalMirror") # This requires LocalMirror repo configuration. expect(@provider).to receive(:shell_out!). - with("pkg delete -y zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) + with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end end diff --git a/spec/unit/provider/package/freebsd/port_spec.rb b/spec/unit/provider/package/freebsd/port_spec.rb index 4ae8d960a2..5c87483fa6 100644 --- a/spec/unit/provider/package/freebsd/port_spec.rb +++ b/spec/unit/provider/package/freebsd/port_spec.rb @@ -68,7 +68,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should check 'pkg_info' if system uses pkg_* tools" do allow(@new_resource).to receive(:supports_pkgng?) expect(@new_resource).to receive(:supports_pkgng?).and_return(false) - expect(@provider).to receive(:shell_out!).with('pkg_info -E "zsh*"', env: nil, returns: [0, 1], timeout: 900).and_return(@pkg_info) + expect(@provider).to receive(:shell_out!).with("pkg_info", "-E", "zsh*", env: nil, returns: [0, 1], timeout: 900).and_return(@pkg_info) expect(@provider.current_installed_version).to eq("3.1.7") end @@ -76,8 +76,8 @@ describe Chef::Provider::Package::Freebsd::Port do pkg_enabled = OpenStruct.new(:stdout => "yes\n") [1000016, 1000000, 901503, 902506, 802511].each do |freebsd_version| @node.automatic_attrs[:os_version] = freebsd_version - expect(@new_resource).to receive(:shell_out!).with("make -V WITH_PKGNG", env: nil).and_return(pkg_enabled) - expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) + expect(@new_resource).to receive(:shell_out!).with("make", "-V", "WITH_PKGNG", env: nil).and_return(pkg_enabled) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "zsh", env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) expect(@provider.current_installed_version).to eq("3.1.7") end end @@ -85,7 +85,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should check 'pkg info' if the freebsd version is greater than or equal to 1000017" do freebsd_version = 1000017 @node.automatic_attrs[:os_version] = freebsd_version - expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "zsh", env: nil, returns: [0, 70], timeout: 900).and_return(@pkg_info) expect(@provider.current_installed_version).to eq("3.1.7") end end @@ -98,7 +98,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should return candidate version if port exists" do allow(::File).to receive(:exist?).with("/usr/ports/Makefile").and_return(true) allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out!).with("make -V PORTVERSION", cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900). + expect(@provider).to receive(:shell_out!).with("make", "-V", "PORTVERSION", cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900). and_return(@port_version) expect(@provider.candidate_version).to eq("5.0.5") end @@ -122,13 +122,13 @@ describe Chef::Provider::Package::Freebsd::Port do it "should query system for path given just a name" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh\n") - expect(@provider).to receive(:shell_out!).with("whereis -s zsh", env: nil, timeout: 900).and_return(whereis) + expect(@provider).to receive(:shell_out!).with("whereis", "-s", "zsh", env: nil, timeout: 900).and_return(whereis) expect(@provider.port_dir).to eq("/usr/ports/shells/zsh") end it "should raise exception if not found" do whereis = OpenStruct.new(:stdout => "zsh:\n") - expect(@provider).to receive(:shell_out!).with("whereis -s zsh", env: nil, timeout: 900).and_return(whereis) + expect(@provider).to receive(:shell_out!).with("whereis", "-s", "zsh", env: nil, timeout: 900).and_return(whereis) expect { @provider.port_dir }.to raise_error(Chef::Exceptions::Package, "Could not find port with the name zsh") end end @@ -141,7 +141,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should run make install in port directory" do allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") expect(@provider).to receive(:shell_out!). - with("make -DBATCH install clean", :timeout => 1800, :cwd => "/usr/ports/shells/zsh", :env => nil). + with("make", "-DBATCH", "install", "clean", :timeout => 1800, :cwd => "/usr/ports/shells/zsh", :env => nil). and_return(@install_result) @provider.install_package("zsh", "5.0.5") end @@ -155,7 +155,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should run make deinstall in port directory" do allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") expect(@provider).to receive(:shell_out!). - with("make deinstall", :timeout => 300, :cwd => "/usr/ports/shells/zsh", :env => nil). + with("make", "deinstall", :timeout => 300, :cwd => "/usr/ports/shells/zsh", :env => nil). and_return(@install_result) @provider.remove_package("zsh", "5.0.5") end diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb index 17ed5ccc41..572c54e83d 100644 --- a/spec/unit/provider/package/homebrew_spec.rb +++ b/spec/unit/provider/package/homebrew_spec.rb @@ -209,7 +209,7 @@ describe Chef::Provider::Package::Homebrew do allow(provider.new_resource).to receive(:version).and_return("24.3") allow(provider.current_resource).to receive(:version).and_return(nil) allow(provider).to receive(:brew_info).and_return(uninstalled_brew_info) - expect(provider).to receive(:get_response_from_command).with("brew install emacs") + expect(provider).to receive(:get_response_from_command).with("brew", "install", nil, "emacs") provider.install_package("emacs", "24.3") end @@ -221,9 +221,9 @@ describe Chef::Provider::Package::Homebrew do end it "uses options to the brew command if specified" do - allow(provider.new_resource).to receive(:options).and_return("--cocoa") + new_resource.options "--cocoa" allow(provider.current_resource).to receive(:version).and_return("24.3") - allow(provider).to receive(:get_response_from_command).with("brew install --cocoa emacs") + allow(provider).to receive(:get_response_from_command).with("brew", "install", "--cocoa", "emacs") provider.install_package("emacs", "24.3") end end @@ -232,7 +232,7 @@ describe Chef::Provider::Package::Homebrew do it "uses brew upgrade to upgrade the package if it is installed" do allow(provider.current_resource).to receive(:version).and_return("24") allow(provider).to receive(:brew_info).and_return(installed_brew_info) - expect(provider).to receive(:get_response_from_command).with("brew upgrade emacs") + expect(provider).to receive(:get_response_from_command).with("brew", "upgrade", nil, "emacs") provider.upgrade_package("emacs", "24.3") end @@ -246,15 +246,15 @@ describe Chef::Provider::Package::Homebrew do it "uses brew install to install the package if it is not installed" do allow(provider.current_resource).to receive(:version).and_return(nil) allow(provider).to receive(:brew_info).and_return(uninstalled_brew_info) - expect(provider).to receive(:get_response_from_command).with("brew install emacs") + expect(provider).to receive(:get_response_from_command).with("brew", "install", nil, "emacs") provider.upgrade_package("emacs", "24.3") end it "uses options to the brew command if specified" do allow(provider.current_resource).to receive(:version).and_return("24") allow(provider).to receive(:brew_info).and_return(installed_brew_info) - allow(provider.new_resource).to receive(:options).and_return("--cocoa") - expect(provider).to receive(:get_response_from_command).with("brew upgrade --cocoa emacs") + new_resource.options "--cocoa" + expect(provider).to receive(:get_response_from_command).with("brew", "upgrade", [ "--cocoa" ], "emacs") provider.upgrade_package("emacs", "24.3") end end @@ -263,7 +263,7 @@ describe Chef::Provider::Package::Homebrew do it "uninstalls the package with brew uninstall" do allow(provider.current_resource).to receive(:version).and_return("24.3") allow(provider).to receive(:brew_info).and_return(installed_brew_info) - expect(provider).to receive(:get_response_from_command).with("brew uninstall emacs") + expect(provider).to receive(:get_response_from_command).with("brew", "uninstall", nil, "emacs") provider.remove_package("emacs", "24.3") end @@ -278,7 +278,7 @@ describe Chef::Provider::Package::Homebrew do it "uninstalls the package with brew uninstall --force" do allow(provider.current_resource).to receive(:version).and_return("24.3") allow(provider).to receive(:brew_info).and_return(installed_brew_info) - expect(provider).to receive(:get_response_from_command).with("brew uninstall --force emacs") + expect(provider).to receive(:get_response_from_command).with("brew", "uninstall", "--force", nil, "emacs") provider.purge_package("emacs", "24.3") end diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb index 0dc433b518..156adf402a 100644 --- a/spec/unit/provider/package/ips_spec.rb +++ b/spec/unit/provider/package/ips_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan <btm@chef.io> -# Copyright:: Copyright 2012-2016, Chef Software Inc. +# Copyright:: Copyright 2012-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,9 +26,9 @@ describe Chef::Provider::Package::Ips do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context) - @current_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context) - allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) + @new_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context) + @current_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context) + allow(Chef::Resource::IpsPackage).to receive(:new).and_return(@current_resource) @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context) end @@ -64,28 +64,28 @@ PKG_STATUS context "when loading current resource" do it "should create a current resource with the name of the new_resource" do - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) - expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) + expect(Chef::Resource::IpsPackage).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources package name to the new resources package name" do - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) @provider.load_current_resource expect(@current_resource.package_name).to eq(@new_resource.package_name) end it "should run pkg info with the package name" do - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) @provider.load_current_resource end it "should set the installed version to nil on the current resource if package state is not installed" do - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) @provider.load_current_resource expect(@current_resource.version).to be_nil end @@ -107,33 +107,33 @@ Packaging Date: October 19, 2011 09:14:50 AM Size: 8.07 MB FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z INSTALLED - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) @provider.load_current_resource expect(@current_resource.version).to eq("2.0.17") end it "should return the current resource" do - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote_output) expect(@provider.load_current_resource).to eql(@current_resource) end end context "when installing a package" do it "should run pkg install with the package name and version" do - expect(@provider).to receive(:shell_out!).with("pkg install -q crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "install", "-q", "crypto/gnupg@2.0.17", timeout: 900) @provider.install_package("crypto/gnupg", "2.0.17") end it "should run pkg install with the package name and version and options if specified" do - expect(@provider).to receive(:shell_out!).with("pkg --no-refresh install -q crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) - allow(@new_resource).to receive(:options).and_return("--no-refresh") + expect(@provider).to receive(:shell_out!).with("pkg", "--no-refresh", "install", "-q", "crypto/gnupg@2.0.17", timeout: 900) + @new_resource.options "--no-refresh" @provider.install_package("crypto/gnupg", "2.0.17") end it "raises an error if package fails to install" do - expect(@provider).to receive(:shell_out!).with("pkg --no-refresh install -q crypto/gnupg@2.0.17", timeout: 900).and_raise(Mixlib::ShellOut::ShellCommandFailed) + expect(@provider).to receive(:shell_out!).with("pkg", "--no-refresh", "install", "-q", "crypto/gnupg@2.0.17", timeout: 900).and_raise(Mixlib::ShellOut::ShellCommandFailed) allow(@new_resource).to receive(:options).and_return("--no-refresh") expect { @provider.install_package("crypto/gnupg", "2.0.17") }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end @@ -152,8 +152,8 @@ Packaging Date: April 1, 2012 05:55:52 PM Size: 2.57 MB FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z PKG_STATUS - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local_output) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote) @provider.load_current_resource expect(@current_resource.version).to be_nil expect(@provider.candidate_version).to eql("1.8.4.1") @@ -193,8 +193,8 @@ Packaging Date: October 19, 2011 09:14:50 AM FMRI: pkg://solaris/crypto/gnupg@2.0.18,5.11-0.175.0.0.0.2.537:20111019T091450Z REMOTE - expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}", timeout: 900).and_return(local) - expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}", timeout: 900).and_return(remote) + expect(@provider).to receive(:shell_out).with("pkg", "info", @new_resource.package_name, timeout: 900).and_return(local) + expect(@provider).to receive(:shell_out!).with("pkg", "info", "-r", @new_resource.package_name, timeout: 900).and_return(remote) expect(@provider).to receive(:install_package).exactly(0).times @provider.run_action(:install) end @@ -205,7 +205,7 @@ REMOTE end it "should run pkg install with the --accept flag" do - expect(@provider).to receive(:shell_out).with("pkg install -q --accept crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out).with("pkg", "install", "-q", "--accept", "crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) @provider.install_package("crypto/gnupg", "2.0.17") end end @@ -213,20 +213,20 @@ REMOTE context "when upgrading a package" do it "should run pkg install with the package name and version" do - expect(@provider).to receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) + expect(@provider).to receive(:shell_out).with("pkg", "install", "-q", "crypto/gnupg@2.0.17", timeout: 900).and_return(local_output) @provider.upgrade_package("crypto/gnupg", "2.0.17") end end context "when uninstalling a package" do it "should run pkg uninstall with the package name and version" do - expect(@provider).to receive(:shell_out!).with("pkg uninstall -q crypto/gnupg@2.0.17", timeout: 900) + expect(@provider).to receive(:shell_out!).with("pkg", "uninstall", "-q", "crypto/gnupg@2.0.17", timeout: 900) @provider.remove_package("crypto/gnupg", "2.0.17") end it "should run pkg uninstall with the package name and version and options if specified" do - expect(@provider).to receive(:shell_out!).with("pkg --no-refresh uninstall -q crypto/gnupg@2.0.17", timeout: 900) - allow(@new_resource).to receive(:options).and_return("--no-refresh") + expect(@provider).to receive(:shell_out!).with("pkg", "--no-refresh", "uninstall", "-q", "crypto/gnupg@2.0.17", timeout: 900) + @new_resource.options "--no-refresh" @provider.remove_package("crypto/gnupg", "2.0.17") end end diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb index b90cf89047..d690791d16 100644 --- a/spec/unit/provider/package/macports_spec.rb +++ b/spec/unit/provider/package/macports_spec.rb @@ -105,7 +105,7 @@ EOF it "should run the port install command with the correct version" do expect(@current_resource).to receive(:version).and_return("4.1.6") @provider.current_resource = @current_resource - expect(@provider).to receive(:shell_out!).with("port install zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "install", "zsh", "@4.2.7", timeout: 900) @provider.install_package("zsh", "4.2.7") end @@ -122,7 +122,7 @@ EOF expect(@current_resource).to receive(:version).and_return("4.1.6") @provider.current_resource = @current_resource allow(@new_resource).to receive(:options).and_return("-f") - expect(@provider).to receive(:shell_out!).with("port -f install zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "-f", "install", "zsh", "@4.2.7", timeout: 900) @provider.install_package("zsh", "4.2.7") end @@ -130,36 +130,36 @@ EOF describe "purge_package" do it "should run the port uninstall command with the correct version" do - expect(@provider).to receive(:shell_out!).with("port uninstall zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "uninstall", "zsh", "@4.2.7", timeout: 900) @provider.purge_package("zsh", "4.2.7") end it "should purge the currently active version if no explicit version is passed in" do - expect(@provider).to receive(:shell_out!).with("port uninstall zsh", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "uninstall", "zsh", timeout: 900) @provider.purge_package("zsh", nil) end it "should add options to the port command when specified" do allow(@new_resource).to receive(:options).and_return("-f") - expect(@provider).to receive(:shell_out!).with("port -f uninstall zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "-f", "uninstall", "zsh", "@4.2.7", timeout: 900) @provider.purge_package("zsh", "4.2.7") end end describe "remove_package" do it "should run the port deactivate command with the correct version" do - expect(@provider).to receive(:shell_out!).with("port deactivate zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "deactivate", "zsh", "@4.2.7", timeout: 900) @provider.remove_package("zsh", "4.2.7") end it "should remove the currently active version if no explicit version is passed in" do - expect(@provider).to receive(:shell_out!).with("port deactivate zsh", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "deactivate", "zsh", timeout: 900) @provider.remove_package("zsh", nil) end it "should add options to the port command when specified" do allow(@new_resource).to receive(:options).and_return("-f") - expect(@provider).to receive(:shell_out!).with("port -f deactivate zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "-f", "deactivate", "zsh", "@4.2.7", timeout: 900) @provider.remove_package("zsh", "4.2.7") end end @@ -169,7 +169,7 @@ EOF expect(@current_resource).to receive(:version).at_least(:once).and_return("4.1.6") @provider.current_resource = @current_resource - expect(@provider).to receive(:shell_out!).with("port upgrade zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "upgrade", "zsh", "@4.2.7", timeout: 900) @provider.upgrade_package("zsh", "4.2.7") end @@ -195,7 +195,7 @@ EOF expect(@current_resource).to receive(:version).at_least(:once).and_return("4.1.6") @provider.current_resource = @current_resource - expect(@provider).to receive(:shell_out!).with("port -f upgrade zsh @4.2.7", timeout: 900) + expect(@provider).to receive(:shell_out!).with("port", "-f", "upgrade", "zsh", "@4.2.7", timeout: 900) @provider.upgrade_package("zsh", "4.2.7") end diff --git a/spec/unit/provider/package/openbsd_spec.rb b/spec/unit/provider/package/openbsd_spec.rb index 3e1c1c90b6..20eb85dfcf 100644 --- a/spec/unit/provider/package/openbsd_spec.rb +++ b/spec/unit/provider/package/openbsd_spec.rb @@ -45,17 +45,17 @@ describe Chef::Provider::Package::Openbsd do context "when not already installed" do before do - allow(provider).to receive(:shell_out!).with("pkg_info -e \"#{name}->0\"", anything()).and_return(instance_double("shellout", :stdout => "")) + allow(provider).to receive(:shell_out!).with("pkg_info", "-e", "#{name}->0", anything()).and_return(instance_double("shellout", :stdout => "")) end context "when there is a single candidate" do context "when source is not provided" do it "should run the installation command" do - expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return( + expect(provider).to receive(:shell_out!).with("pkg_info", "-I", name, anything()).and_return( instance_double("shellout", :stdout => "#{name}-#{version}\n")) expect(provider).to receive(:shell_out!).with( - "pkg_add -r #{name}-#{version}", + "pkg_add", "-r", "#{name}-#{version}", { :env => { "PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/" }, timeout: 900 } ) { OpenStruct.new :status => true } provider.run_action(:install) @@ -69,7 +69,7 @@ describe Chef::Provider::Package::Openbsd do context "if no version is specified" do it "should raise an exception" do - expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return( + expect(provider).to receive(:shell_out!).with("pkg_info", "-I", name, anything()).and_return( instance_double("shellout", :stdout => "#{name}-#{version}-#{flavor_a}\n#{name}-#{version}-#{flavor_b}\n")) expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /multiple matching candidates/) end @@ -83,11 +83,11 @@ describe Chef::Provider::Package::Openbsd do context "if no version is specified" do it "should run the installation command" do - expect(provider).to receive(:shell_out!).with("pkg_info -e \"#{package_name}->0\"", anything()).and_return(instance_double("shellout", :stdout => "")) - expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}\"", anything()).and_return( + expect(provider).to receive(:shell_out!).with("pkg_info", "-e", "#{package_name}->0", anything()).and_return(instance_double("shellout", :stdout => "")) + expect(provider).to receive(:shell_out!).with("pkg_info", "-I", name, anything()).and_return( instance_double("shellout", :stdout => "#{name}-#{version}-#{flavor}\n")) expect(provider).to receive(:shell_out!).with( - "pkg_add -r #{name}-#{version}-#{flavor}", + "pkg_add", "-r", "#{name}-#{version}-#{flavor}", { env: { "PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/" }, timeout: 900 } ) { OpenStruct.new :status => true } provider.run_action(:install) @@ -98,12 +98,12 @@ describe Chef::Provider::Package::Openbsd do context "if a version is specified" do it "should use the flavor from the version" do - expect(provider).to receive(:shell_out!).with("pkg_info -I \"#{name}-#{version}-#{flavor_b}\"", anything()).and_return( + expect(provider).to receive(:shell_out!).with("pkg_info", "-I", "#{name}-#{version}-#{flavor_b}", anything()).and_return( instance_double("shellout", :stdout => "#{name}-#{version}-#{flavor_a}\n")) new_resource.version("#{version}-#{flavor_b}") expect(provider).to receive(:shell_out!).with( - "pkg_add -r #{name}-#{version}-#{flavor_b}", + "pkg_add", "-r", "#{name}-#{version}-#{flavor_b}", { env: { "PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/" }, timeout: 900 } ) { OpenStruct.new :status => true } provider.run_action(:install) @@ -123,7 +123,7 @@ describe Chef::Provider::Package::Openbsd do end it "should run the command to delete the installed package" do expect(@provider).to receive(:shell_out!).with( - "pkg_delete #{@name}", env: nil, timeout: 900 + "pkg_delete", @name, env: nil, timeout: 900 ) { OpenStruct.new :status => true } @provider.remove_package(@name, nil) end diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index ce9107f31b..32af9e4bd2 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -51,7 +51,7 @@ ERR end it "should run pacman query with the package name" do - expect(@provider).to receive(:shell_out).with("pacman -Qi #{@new_resource.package_name}", { timeout: 900 }).and_return(@status) + expect(@provider).to receive(:shell_out).with("pacman", "-Qi", @new_resource.package_name, { timeout: 900 }).and_return(@status) @provider.load_current_resource end @@ -121,7 +121,7 @@ Include = /etc/pacman.d/mirrorlist PACMAN_CONF status = double(:stdout => "customrepo nano 1.2.3-4", :exitstatus => 0) - allow(::File).to receive(:exists?).with("/etc/pacman.conf").and_return(true) + allow(::File).to receive(:exist?).with("/etc/pacman.conf").and_return(true) allow(::File).to receive(:read).with("/etc/pacman.conf").and_return(@pacman_conf) allow(@provider).to receive(:shell_out).and_return(status) @@ -151,12 +151,12 @@ PACMAN_CONF describe Chef::Provider::Package::Pacman, "install_package" do it "should run pacman install with the package name and version" do - expect(@provider).to receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar nano", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pacman", "--sync", "--noconfirm", "--noprogressbar", "nano", { timeout: 900 }) @provider.install_package("nano", "1.0") end it "should run pacman install with the package name and version and options if specified" do - expect(@provider).to receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar --debug nano", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pacman", "--sync", "--noconfirm", "--noprogressbar", "--debug", "nano", { timeout: 900 }) allow(@new_resource).to receive(:options).and_return("--debug") @provider.install_package("nano", "1.0") @@ -172,12 +172,12 @@ PACMAN_CONF describe Chef::Provider::Package::Pacman, "remove_package" do it "should run pacman remove with the package name" do - expect(@provider).to receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar nano", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pacman", "--remove", "--noconfirm", "--noprogressbar", "nano", { timeout: 900 }) @provider.remove_package("nano", "1.0") end it "should run pacman remove with the package name and options if specified" do - expect(@provider).to receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar --debug nano", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pacman", "--remove", "--noconfirm", "--noprogressbar", "--debug", "nano", { timeout: 900 }) allow(@new_resource).to receive(:options).and_return("--debug") @provider.remove_package("nano", "1.0") diff --git a/spec/unit/provider/package/paludis_spec.rb b/spec/unit/provider/package/paludis_spec.rb index b984aeb83f..df0150c8c0 100644 --- a/spec/unit/provider/package/paludis_spec.rb +++ b/spec/unit/provider/package/paludis_spec.rb @@ -59,7 +59,7 @@ PKG_STATUS end it "should run pkg info with the package name" do - expect(@provider).to receive(:shell_out!).with("cave -L warning print-ids -M none -m \"#{@new_resource.package_name}\" -f \"%c/%p %v %r\n\"").and_return(@shell_out) + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "print-ids", "-M", "none", "-m", @new_resource.package_name, "-f", "%c/%p %v %r\n").and_return(@shell_out) @provider.load_current_resource end @@ -86,13 +86,13 @@ INSTALLED context "when installing a package" do it "should run pkg install with the package name and version" do - expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", { :timeout => @new_resource.timeout }) + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "resolve", "-x", "=net/ntp-4.2.6_p5-r2", { :timeout => @new_resource.timeout || 900 }) @provider.install_package("net/ntp", "4.2.6_p5-r2") end it "should run pkg install with the package name and version and options if specified" do - expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x --preserve-world \"=net/ntp-4.2.6_p5-r2\"", { :timeout => @new_resource.timeout }) - allow(@new_resource).to receive(:options).and_return("--preserve-world") + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "resolve", "-x", "--preserve-world", "=net/ntp-4.2.6_p5-r2", { :timeout => @new_resource.timeout || 900 }) + @new_resource.options "--preserve-world" @provider.install_package("net/ntp", "4.2.6_p5-r2") end @@ -101,7 +101,7 @@ INSTALLED sys-process/lsof 4.87 arbor sys-process/lsof 4.87 x86_64 PKG_STATUS - expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"", { :timeout => @new_resource.timeout }) + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "resolve", "-x", "=sys-process/lsof-4.87", { :timeout => @new_resource.timeout || 900 }) @provider.install_package("sys-process/lsof", "4.87") end @@ -119,14 +119,14 @@ PKG_STATUS context "when upgrading a package" do it "should run pkg install with the package name and version" do - expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", { :timeout => @new_resource.timeout }) + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "resolve", "-x", "=net/ntp-4.2.6_p5-r2", { :timeout => @new_resource.timeout || 900 }) @provider.upgrade_package("net/ntp", "4.2.6_p5-r2") end end context "when uninstalling a package" do it "should run pkg uninstall with the package name and version" do - expect(@provider).to receive(:shell_out!).with("cave -L warning uninstall -x \"=net/ntp-4.2.6_p5-r2\"") + expect(@provider).to receive(:shell_out!).with("cave", "-L", "warning", "uninstall", "-x", "=net/ntp-4.2.6_p5-r2") @provider.remove_package("net/ntp", "4.2.6_p5-r2") end diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb index ebb5b3139f..d77e180181 100644 --- a/spec/unit/provider/package/portage_spec.rb +++ b/spec/unit/provider/package/portage_spec.rb @@ -284,31 +284,30 @@ EOF describe Chef::Provider::Package::Portage, "install_package" do it "should install a normally versioned package using portage" do - expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet =dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge", "-g", "--color", "n", "--nospinner", "--quiet", "=dev-util/git-1.0.0") @provider.install_package("dev-util/git", "1.0.0") end it "should install a tilde versioned package using portage" do - expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet ~dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge", "-g", "--color", "n", "--nospinner", "--quiet", "~dev-util/git-1.0.0") @provider.install_package("dev-util/git", "~1.0.0") end it "should add options to the emerge command when specified" do - expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0") - allow(@new_resource).to receive(:options).and_return("--oneshot") - + expect(@provider).to receive(:shell_out!).with("emerge", "-g", "--color", "n", "--nospinner", "--quiet", "--oneshot", "=dev-util/git-1.0.0") + @new_resource.options "--oneshot" @provider.install_package("dev-util/git", "1.0.0") end end describe Chef::Provider::Package::Portage, "remove_package" do it "should un-emerge the package with no version specified" do - expect(@provider).to receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet dev-util/git") + expect(@provider).to receive(:shell_out!).with("emerge", "--unmerge", "--color", "n", "--nospinner", "--quiet", "dev-util/git") @provider.remove_package("dev-util/git", nil) end it "should un-emerge the package with a version specified" do - expect(@provider).to receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet =dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge", "--unmerge", "--color", "n", "--nospinner", "--quiet", "=dev-util/git-1.0.0") @provider.remove_package("dev-util/git", "1.0.0") end end diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb index 1d179edf76..3730878026 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(:exists?).with("PLEASE STUB File.exists? EXACTLY").and_return(true) + allow(::File).to receive(:exist?).with("PLEASE STUB File.exists? EXACTLY").and_return(true) # Ensure all shell out usage is stubbed with exact arguments allow(provider).to receive(:shell_out!).with("PLEASE STUB YOUR SHELLOUT CALLS").and_return(nil) @@ -61,7 +61,7 @@ describe Chef::Provider::Package::Rpm do context "when the source is a file that doesn't exist" do it "should raise an exception when attempting any action" do - allow(::File).to receive(:exists?).with(package_source).and_return(false) + allow(::File).to receive(:exist?).with(package_source).and_return(false) expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package) end end @@ -71,7 +71,7 @@ describe Chef::Provider::Package::Rpm do let(:package_source) { "foobar://example.com/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" } it "should raise an exception if an uri formed source is non-supported scheme" do - allow(::File).to receive(:exists?).with(package_source).and_return(false) + allow(::File).to receive(:exist?).with(package_source).and_return(false) # verify let bindings are as we expect expect(new_resource.source).to eq("foobar://example.com/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @@ -86,18 +86,18 @@ describe Chef::Provider::Package::Rpm do before do expect(provider).to receive(:shell_out!). - with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{package_source}", timeout: 900). + with("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_source, timeout: 900). and_return(rpm_qp_status) expect(provider).to receive(:shell_out). - with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{package_name}", timeout: 900). + with("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_name, timeout: 900). and_return(rpm_q_status) end context "when rpm fails when querying package installed state" do before do - allow(::File).to receive(:exists?).with(package_source).and_return(true) + allow(::File).to receive(:exist?).with(package_source).and_return(true) end let(:rpm_qp_stdout) { "ImageMagick-c++ 6.5.4.7-7.el6_5" } @@ -129,7 +129,7 @@ describe Chef::Provider::Package::Rpm do context "when the source is a file system path" do before do - allow(::File).to receive(:exists?).with(package_source).and_return(true) + allow(::File).to receive(:exist?).with(package_source).and_return(true) provider.action = action @@ -151,7 +151,7 @@ describe Chef::Provider::Package::Rpm do context "when at the desired version already" do it "does nothing when the correct version is installed" do - expect(provider).to_not receive(:shell_out!).with("rpm -i /tmp/imagemagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to_not receive(:shell_out!).with("rpm", "-i", "/tmp/imagemagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_install end @@ -162,7 +162,7 @@ describe Chef::Provider::Package::Rpm do let(:rpm_q_stdout) { "imagemagick-c++ 0.5.4.7-7.el6_5" } it "runs rpm -u with the package source to upgrade" do - expect(provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_install end end @@ -178,7 +178,7 @@ describe Chef::Provider::Package::Rpm do let(:rpm_q_stdout) { "imagemagick-c++ 21.4-19.el6_5" } it "should run rpm -u --oldpackage with the package source to downgrade" do - expect(provider).to receive(:shell_out!).with("rpm -U --oldpackage /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-U", "--oldpackage", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_install end @@ -192,7 +192,7 @@ describe Chef::Provider::Package::Rpm do context "when at the desired version already" do it "does nothing when the correct version is installed" do - expect(provider).to_not receive(:shell_out!).with("rpm -i /tmp/imagemagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to_not receive(:shell_out!).with("rpm", "-i", "/tmp/imagemagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_upgrade end @@ -203,7 +203,7 @@ describe Chef::Provider::Package::Rpm do let(:rpm_q_stdout) { "imagemagick-c++ 0.5.4.7-7.el6_5" } it "runs rpm -u with the package source to upgrade" do - expect(provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_upgrade end end @@ -219,7 +219,7 @@ describe Chef::Provider::Package::Rpm do let(:rpm_q_stdout) { "imagemagick-c++ 21.4-19.el6_5" } it "should run rpm -u --oldpackage with the package source to downgrade" do - expect(provider).to receive(:shell_out!).with("rpm -U --oldpackage /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-U", "--oldpackage", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.action_upgrade end @@ -231,7 +231,7 @@ describe Chef::Provider::Package::Rpm do let(:action) { :remove } it "should remove the package" do - expect(provider).to receive(:shell_out!).with("rpm -e ImageMagick-c++-6.5.4.7-7.el6_5", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-e", "ImageMagick-c++-6.5.4.7-7.el6_5", timeout: 900) provider.action_remove end end @@ -276,7 +276,7 @@ describe Chef::Provider::Package::Rpm do context "when the source is given as an URI" do before(:each) do - allow(::File).to receive(:exists?).with(package_source).and_return(false) + allow(::File).to receive(:exist?).with(package_source).and_return(false) provider.action = action @@ -322,7 +322,7 @@ describe Chef::Provider::Package::Rpm do let(:action) { :install } before do - allow(File).to receive(:exists?).with(package_source).and_return(true) + allow(File).to receive(:exist?).with(package_source).and_return(true) provider.action = action @@ -357,7 +357,7 @@ describe Chef::Provider::Package::Rpm do describe "action install" do it "installs the package" do - expect(provider).to receive(:shell_out!).with("rpm -i #{package_source}", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-i", package_source, timeout: 900) provider.action_install end @@ -365,7 +365,7 @@ describe Chef::Provider::Package::Rpm do context "when custom resource options are given" do it "installs with custom options specified in the resource" do new_resource.options("--dbpath /var/lib/rpm") - expect(provider).to receive(:shell_out!).with("rpm --dbpath /var/lib/rpm -i #{package_source}", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "--dbpath", "/var/lib/rpm", "-i", package_source, timeout: 900) provider.action_install end end @@ -376,7 +376,7 @@ describe Chef::Provider::Package::Rpm do let(:action) { :upgrade } it "installs the package" do - expect(provider).to receive(:shell_out!).with("rpm -i #{package_source}", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-i", package_source, timeout: 900) provider.action_upgrade end @@ -387,7 +387,7 @@ describe Chef::Provider::Package::Rpm do let(:action) { :remove } it "should do nothing" do - expect(provider).to_not receive(:shell_out!).with("rpm -e ImageMagick-c++-6.5.4.7-7.el6_5", timeout: 900) + expect(provider).to_not receive(:shell_out!).with("rpm", "-e", "ImageMagick-c++-6.5.4.7-7.el6_5", timeout: 900) provider.action_remove end end @@ -404,7 +404,7 @@ describe Chef::Provider::Package::Rpm do # provider will call File.exists?. Because of the ordering in our # let() bindings and such, we have to set the stub here and not in a # before block. - allow(::File).to receive(:exists?).with(package_source).and_return(true) + allow(::File).to receive(:exist?).with(package_source).and_return(true) Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") end @@ -413,7 +413,7 @@ describe Chef::Provider::Package::Rpm do it "should install from a path when the package is a path and the source is nil" do expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") provider.current_resource = current_resource - expect(provider).to receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-i", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end @@ -421,7 +421,7 @@ describe Chef::Provider::Package::Rpm do expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") current_resource.version("21.4-19.el5") provider.current_resource = current_resource - expect(provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) + expect(provider).to receive(:shell_out!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900) provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end end diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index 548204df75..53c82f2f70 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -144,30 +144,30 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do it "installs a gem with a hash of options for the dependency installer" do dep_installer = Gem::DependencyInstaller.new - expect(@gem_env).to receive(:dependency_installer).with(:install_dir => "/foo/bar").and_return(dep_installer) + expect(@gem_env).to receive(:dependency_installer).with(install_dir: "/foo/bar").and_return(dep_installer) expect(@gem_env).to receive(:with_gem_sources).with("http://gems.example.com").and_yield expect(dep_installer).to receive(:install).with(Gem::Dependency.new("rspec", ">= 0")) - @gem_env.install(Gem::Dependency.new("rspec", ">= 0"), :install_dir => "/foo/bar", :sources => ["http://gems.example.com"]) + @gem_env.install(Gem::Dependency.new("rspec", ">= 0"), install_dir: "/foo/bar", sources: ["http://gems.example.com"]) end it "builds an uninstaller for a gem with options set to avoid requiring user input" do # default options for uninstaller should be: # :ignore => true, :executables => true - expect(Gem::Uninstaller).to receive(:new).with("rspec", :ignore => true, :executables => true) + expect(Gem::Uninstaller).to receive(:new).with("rspec", ignore: true, executables: true) @gem_env.uninstaller("rspec") end it "uninstalls all versions of a gem" do uninstaller = double("gem uninstaller") expect(uninstaller).to receive(:uninstall) - expect(@gem_env).to receive(:uninstaller).with("rspec", :all => true).and_return(uninstaller) + expect(@gem_env).to receive(:uninstaller).with("rspec", all: true).and_return(uninstaller) @gem_env.uninstall("rspec") end it "uninstalls a specific version of a gem" do uninstaller = double("gem uninstaller") expect(uninstaller).to receive(:uninstall) - expect(@gem_env).to receive(:uninstaller).with("rspec", :version => "1.2.3").and_return(uninstaller) + expect(@gem_env).to receive(:uninstaller).with("rspec", version: "1.2.3").and_return(uninstaller) @gem_env.uninstall("rspec", "1.2.3") end @@ -184,14 +184,14 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do it "determines the gem paths from shelling out to gem env" do gem_env_output = ["/path/to/gems", "/another/path/to/gems"].join(File::PATH_SEPARATOR) - shell_out_result = OpenStruct.new(:stdout => gem_env_output) + shell_out_result = OpenStruct.new(stdout: gem_env_output) expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env gempath").and_return(shell_out_result) expect(@gem_env.gem_paths).to eq(["/path/to/gems", "/another/path/to/gems"]) end it "caches the gempaths by gem_binary" do gem_env_output = ["/path/to/gems", "/another/path/to/gems"].join(File::PATH_SEPARATOR) - shell_out_result = OpenStruct.new(:stdout => gem_env_output) + shell_out_result = OpenStruct.new(stdout: gem_env_output) expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env gempath").and_return(shell_out_result) expected = ["/path/to/gems", "/another/path/to/gems"] expect(@gem_env.gem_paths).to eq(["/path/to/gems", "/another/path/to/gems"]) @@ -271,7 +271,7 @@ RubyGems Environment: - https://rubygems.org/ - http://gems.github.com/ JRUBY_GEM_ENV - expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env").and_return(double("jruby_gem_env", :stdout => gem_env_out)) + expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env").and_return(double("jruby_gem_env", stdout: gem_env_out)) expected = ["ruby", Gem::Platform.new("universal-java-1.6")] expect(@gem_env.gem_platforms).to eq(expected) # it should also cache the result @@ -313,7 +313,7 @@ RubyGems Environment: - https://rubygems.org/ - http://gems.github.com/ RBX_GEM_ENV - expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env").and_return(double("rbx_gem_env", :stdout => gem_env_out)) + expect(@gem_env).to receive(:shell_out!).with("/usr/weird/bin/gem env").and_return(double("rbx_gem_env", stdout: gem_env_out)) expect(@gem_env.gem_platforms).to eq(Gem.platforms) expect(Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache["/usr/weird/bin/gem"]).to eq(Gem.platforms) end @@ -351,7 +351,7 @@ describe Chef::Provider::Package::Rubygems do new_resource end - let (:current_resource) { nil } + let(:current_resource) { nil } let(:provider) do run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new) @@ -403,7 +403,7 @@ describe Chef::Provider::Package::Rubygems do end context "when you try to use a hash of install options" do - let(:options) { { :fail => :burger } } + let(:options) { { fail: :burger } } it "smites you" do expect { provider }.to raise_error(ArgumentError) @@ -437,9 +437,9 @@ describe Chef::Provider::Package::Rubygems do it "searches for a gem binary when running on Omnibus on Unix" do platform_mock :unix do allow(ENV).to receive(:[]).with("PATH").and_return("/usr/bin:/usr/sbin:/opt/chef/embedded/bin") - allow(File).to receive(:exists?).with("/usr/bin/gem").and_return(false) - allow(File).to receive(:exists?).with("/usr/sbin/gem").and_return(true) - allow(File).to receive(:exists?).with("/opt/chef/embedded/bin/gem").and_return(true) # should not get here + allow(File).to receive(:exist?).with("/usr/bin/gem").and_return(false) + allow(File).to receive(:exist?).with("/usr/sbin/gem").and_return(true) + allow(File).to receive(:exist?).with("/opt/chef/embedded/bin/gem").and_return(true) # should not get here expect(provider.gem_env.gem_binary_location).to eq("/usr/sbin/gem") end end @@ -450,11 +450,11 @@ describe Chef::Provider::Package::Rubygems do it "searches for a gem binary when running on Omnibus on Windows" do platform_mock :windows do allow(ENV).to receive(:[]).with("PATH").and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin;d:\opscode\chef\embedded\bin') - allow(File).to receive(:exists?).with('C:\\windows\\system32\\gem').and_return(false) - allow(File).to receive(:exists?).with('C:\\windows\\gem').and_return(false) - allow(File).to receive(:exists?).with('C:\\Ruby186\\bin\\gem').and_return(true) - allow(File).to receive(:exists?).with('d:\\opscode\\chef\\bin\\gem').and_return(false) # should not get here - allow(File).to receive(:exists?).with('d:\\opscode\\chef\\embedded\\bin\\gem').and_return(false) # should not get here + allow(File).to receive(:exist?).with('C:\\windows\\system32\\gem').and_return(false) + allow(File).to receive(:exist?).with('C:\\windows\\gem').and_return(false) + allow(File).to receive(:exist?).with('C:\\Ruby186\\bin\\gem').and_return(true) + allow(File).to receive(:exist?).with('d:\\opscode\\chef\\bin\\gem').and_return(false) # should not get here + allow(File).to receive(:exist?).with('d:\\opscode\\chef\\embedded\\bin\\gem').and_return(false) # should not get here expect(provider.gem_env.gem_binary_location).to eq('C:\Ruby186\bin\gem') end end @@ -526,8 +526,8 @@ describe Chef::Provider::Package::Rubygems do end it "queries for available versions on upgrade" do - expect(provider.gem_env).to receive(:candidate_version_from_remote). - and_return(Gem::Version.new("9000.0.2")) + expect(provider.gem_env).to receive(:candidate_version_from_remote) + .and_return(Gem::Version.new("9000.0.2")) expect(provider.gem_env).to receive(:install) provider.run_action(:upgrade) expect(new_resource).to be_updated_by_last_action @@ -538,17 +538,17 @@ describe Chef::Provider::Package::Rubygems do let(:source) { "http://mygems.example.com" } it "determines the candidate version by querying the remote gem servers" do - expect(provider.gem_env).to receive(:candidate_version_from_remote). - with(gem_dep, source). - and_return(Gem::Version.new(target_version)) + expect(provider.gem_env).to receive(:candidate_version_from_remote) + .with(gem_dep, source) + .and_return(Gem::Version.new(target_version)) expect(provider.candidate_version).to eq(target_version) end end context "when the requested source is a file" do - let (:gem_name) { "chef-integration-test" } - let (:source) { CHEF_SPEC_DATA + "/gems/chef-integration-test-0.1.0.gem" } - let (:target_version) { ">= 0" } + let(:gem_name) { "chef-integration-test" } + let(:source) { CHEF_SPEC_DATA + "/gems/chef-integration-test-0.1.0.gem" } + let(:target_version) { ">= 0" } it "parses the gem's specification" do expect(provider.candidate_version).to eq("0.1.0") @@ -570,14 +570,14 @@ describe Chef::Provider::Package::Rubygems do version = Gem::Version.new(candidate_version) args = [gem_dep] args << source if source - allow(provider.gem_env).to receive(:candidate_version_from_remote). - with(*args). - and_return(version) + allow(provider.gem_env).to receive(:candidate_version_from_remote) + .with(*args) + .and_return(version) end describe "in the current gem environment" do it "installs the gem via the gems api when no explicit options are used" do - expect(provider.gem_env).to receive(:install).with(gem_dep, :sources => nil) + expect(provider.gem_env).to receive(:install).with(gem_dep, sources: nil) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end @@ -586,7 +586,7 @@ describe Chef::Provider::Package::Rubygems do let(:source) { "http://gems.example.org" } it "installs the gem via the gems api" do - expect(provider.gem_env).to receive(:install).with(gem_dep, :sources => [source]) + expect(provider.gem_env).to receive(:install).with(gem_dep, sources: [source]) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end @@ -615,9 +615,9 @@ describe Chef::Provider::Package::Rubygems do # this catches 'gem_package "foo"' when "./foo" is a file in the cwd, and instead of installing './foo' it fetches the remote gem it "installs the gem via the gems api, when the package has no file separator characters in it, but a matching file exists in cwd" do - allow(::File).to receive(:exists?).and_return(true) + allow(::File).to receive(:exist?).and_return(true) new_resource.package_name("rspec-core") - expect(provider.gem_env).to receive(:install).with(gem_dep, :sources => nil) + expect(provider.gem_env).to receive(:install).with(gem_dep, sources: nil) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end @@ -671,10 +671,10 @@ describe Chef::Provider::Package::Rubygems do end context "when options are given as a Hash" do - let(:options) { { :install_dir => "/alt/install/location" } } + let(:options) { { install_dir: "/alt/install/location" } } it "installs the gem via the gems api when options are given as a Hash" do - expect(provider.gem_env).to receive(:install).with(gem_dep, { :sources => nil }.merge(options)) + expect(provider.gem_env).to receive(:install).with(gem_dep, { sources: nil }.merge(options)) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end @@ -684,7 +684,7 @@ describe Chef::Provider::Package::Rubygems do let(:target_version) { "9000.0.2" } it "installs the gem via the gems api" do - expect(provider.gem_env).to receive(:install).with(gem_dep, :sources => nil) + expect(provider.gem_env).to receive(:install).with(gem_dep, sources: nil) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end @@ -780,7 +780,7 @@ describe Chef::Provider::Package::Rubygems do end context "when options are given as a Hash" do - let(:options) { { :install_dir => "/alt/install/location" } } + let(:options) { { install_dir: "/alt/install/location" } } it "uninstalls via the api" do # pre-reqs for action_remove to actually remove the package: diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb index 9cc8deeb2a..2fba2e3a08 100644 --- a/spec/unit/provider/package/solaris_spec.rb +++ b/spec/unit/provider/package/solaris_spec.rb @@ -27,7 +27,7 @@ describe Chef::Provider::Package::Solaris do @new_resource.source("/tmp/bash.pkg") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) - allow(::File).to receive(:exists?).and_return(true) + allow(::File).to receive(:exist?).and_return(true) end describe "assessing the current package status" do @@ -63,7 +63,7 @@ PKGINFO it "should raise an exception if a source is supplied but not found" do allow(@provider).to receive(:shell_out).and_return(@status) - allow(::File).to receive(:exists?).and_return(false) + allow(::File).to receive(:exist?).and_return(false) @provider.load_current_resource @provider.define_resource_requirements expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package) @@ -71,8 +71,8 @@ PKGINFO it "should get the source package version from pkginfo if provided" do status = double(:stdout => @pkginfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash", { timeout: 900 }).and_return(status) - expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash", { timeout: 900 }).and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "-d", "/tmp/bash.pkg", "SUNWbash", { timeout: 900 }).and_return(status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "SUNWbash", { timeout: 900 }).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("SUNWbash") @@ -81,8 +81,8 @@ PKGINFO it "should return the current version installed if found by pkginfo" do status = double(:stdout => @pkginfo, :exitstatus => 0) - expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash", { timeout: 900 }).and_return(@status) - expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash", { timeout: 900 }).and_return(status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "-d", "/tmp/bash.pkg", "SUNWbash", { timeout: 900 }).and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "SUNWbash", { timeout: 900 }).and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to eq("11.10.0,REV=2005.01.08.05.16") end @@ -101,8 +101,8 @@ PKGINFO end it "should return a current resource with a nil version if the package is not found" do - expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash", { timeout: 900 }).and_return(@status) - expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash", { timeout: 900 }).and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "-d", "/tmp/bash.pkg", "SUNWbash", { timeout: 900 }).and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo", "-l", "SUNWbash", { timeout: 900 }).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.version).to be_nil end @@ -132,7 +132,7 @@ PKGINFO describe "install and upgrade" do it "should run pkgadd -n -d with the package source to install" do - expect(@provider).to receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pkgadd", "-n", "-d", "/tmp/bash.pkg", "all", { timeout: 900 }) @provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end @@ -140,26 +140,26 @@ PKGINFO @new_resource = Chef::Resource::Package.new("/tmp/bash.pkg") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) expect(@new_resource.source).to eq("/tmp/bash.pkg") - expect(@provider).to receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pkgadd", "-n", "-d", "/tmp/bash.pkg", "all", { timeout: 900 }) @provider.install_package("/tmp/bash.pkg", "11.10.0,REV=2005.01.08.05.16") end it "should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin" do - allow(@new_resource).to receive(:options).and_return("-a /tmp/myadmin") - expect(@provider).to receive(:shell_out!).with("pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all", { timeout: 900 }) + @new_resource.options "-a /tmp/myadmin" + expect(@provider).to receive(:shell_out!).with("pkgadd", "-n", "-a", "/tmp/myadmin", "-d", "/tmp/bash.pkg", "all", { timeout: 900 }) @provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end end describe "remove" do it "should run pkgrm -n to remove the package" do - expect(@provider).to receive(:shell_out!).with("pkgrm -n SUNWbash", { timeout: 900 }) + expect(@provider).to receive(:shell_out!).with("pkgrm", "-n", "SUNWbash", { timeout: 900 }) @provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end it "should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin" do - allow(@new_resource).to receive(:options).and_return("-a /tmp/myadmin") - expect(@provider).to receive(:shell_out!).with("pkgrm -n -a /tmp/myadmin SUNWbash", { timeout: 900 }) + @new_resource.options "-a /tmp/myadmin" + expect(@provider).to receive(:shell_out!).with("pkgrm", "-n", "-a", "/tmp/myadmin", "SUNWbash", { timeout: 900 }) @provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index 53cbbc1da1..4b258a078f 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan <btm@loftninjas.org> -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -312,6 +312,7 @@ describe Chef::Provider::Package::Windows, :windows_only do let(:resource_source) { "https://foo.bar/calculator.exe" } it "downloads the http resource" do + allow(File).to receive(:exist?).with('c:\cache\calculator.exe').and_return(false) expect(provider).to receive(:download_source_file) provider.run_action(:install) end diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index babbf9b933..e0a5f8c862 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software, Inc. +# Copyright:: Copyright 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,6 +40,7 @@ describe Chef::Provider::Package::Yum do ) allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache) allow(@yum_cache).to receive(:yum_binary=).with("yum") + allow(::File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @pid = double("PID") end @@ -80,7 +81,7 @@ describe Chef::Provider::Package::Yum do @new_resource = Chef::Resource::YumPackage.new("testing.source") @new_resource.source "chef-server-core-12.0.5-1.rpm" @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) - allow(File).to receive(:exists?).with(@new_resource.source).and_return(true) + allow(File).to receive(:exist?).with(@new_resource.source).and_return(true) allow(@yum_cache).to receive(:installed_version).and_return(nil) shellout_double = double(:stdout => "chef-server-core 12.0.5-1 i386") allow(@provider).to receive(:shell_out!).and_return(shellout_double) @@ -535,7 +536,7 @@ describe Chef::Provider::Package::Yum do it "should run yum localinstall if given a path to an rpm as the package" do @new_resource = Chef::Resource::YumPackage.new("/tmp/emacs-21.4-20.el5.i386.rpm") - allow(::File).to receive(:exists?).and_return(true) + allow(::File).to receive(:exist?).with("/tmp/emacs-21.4-20.el5.i386.rpm").and_return(true) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) expect(@new_resource.source).to eq("/tmp/emacs-21.4-20.el5.i386.rpm") expect(@provider).to receive(:yum_command).with( diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index d2800575bc..7e6f204b64 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -38,14 +38,14 @@ describe Chef::Provider::Package::Zypper do allow(provider).to receive(:`).and_return("2.0") end - def shell_out_expectation(command, options = nil) - options ||= { timeout: 900 } - expect(provider).to receive(:shell_out).with(command, options) + def shell_out_expectation(*command, **options) + options[:timeout] ||= 900 + expect(provider).to receive(:shell_out).with(*command, **options) end - def shell_out_expectation!(command, options = nil) - options ||= { timeout: 900 } - expect(provider).to receive(:shell_out!).with(command, options) + def shell_out_expectation!(*command, **options) + options[:timeout] ||= 900 + expect(provider).to receive(:shell_out!).with(*command, **options) end describe "when loading the current package state" do @@ -61,7 +61,7 @@ describe Chef::Provider::Package::Zypper do it "should run zypper info with the package name" do shell_out_expectation!( - "zypper --non-interactive info #{new_resource.package_name}" + "zypper", "--non-interactive", "info", new_resource.package_name ).and_return(status) provider.load_current_resource end @@ -113,14 +113,14 @@ describe Chef::Provider::Package::Zypper do it "should run zypper install with the package name and version" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.install_package(["emacs"], ["1.0"]) end it "should run zypper install without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.install_package(["emacs"], ["1.0"]) end @@ -129,7 +129,7 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.install_package(["emacs"], ["1.0"]) end @@ -139,14 +139,14 @@ describe Chef::Provider::Package::Zypper do it "should run zypper update with the package name and version" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.upgrade_package(["emacs"], ["1.0"]) end it "should run zypper update without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.upgrade_package(["emacs"], ["1.0"]) end @@ -155,13 +155,13 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.upgrade_package(["emacs"], ["1.0"]) end it "should run zypper upgrade without gpg checks" do shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0" ) provider.upgrade_package(["emacs"], ["1.0"]) end @@ -173,7 +173,7 @@ describe Chef::Provider::Package::Zypper do it "should run zypper remove with the package name" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive remove emacs" + "zypper", "--non-interactive", "remove", "emacs" ) provider.remove_package(["emacs"], [nil]) end @@ -183,14 +183,14 @@ describe Chef::Provider::Package::Zypper do it "should run zypper remove with the package name" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive remove emacs=1.0" + "zypper", "--non-interactive", "remove", "emacs=1.0" ) provider.remove_package(["emacs"], ["1.0"]) end it "should run zypper remove without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "emacs=1.0" ) provider.remove_package(["emacs"], ["1.0"]) end @@ -199,7 +199,7 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "emacs=1.0" ) provider.remove_package(["emacs"], ["1.0"]) end @@ -209,14 +209,14 @@ describe Chef::Provider::Package::Zypper do describe "purge_package" do it "should run remove with the name and version and --clean-deps" do shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "--clean-deps", "emacs=1.0" ) provider.purge_package(["emacs"], ["1.0"]) end it "should run zypper purge without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "--clean-deps", "emacs=1.0" ) provider.purge_package(["emacs"], ["1.0"]) end @@ -225,7 +225,7 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "--clean-deps", "emacs=1.0" ) provider.purge_package(["emacs"], ["1.0"]) end @@ -235,14 +235,14 @@ describe Chef::Provider::Package::Zypper do it "should run zypper addlock with the package name" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive addlock emacs" + "zypper", "--non-interactive", "addlock", "emacs" ) provider.lock_package(["emacs"], [nil]) end it "should run zypper addlock without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks addlock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "addlock", "emacs" ) provider.lock_package(["emacs"], [nil]) end @@ -251,13 +251,13 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks addlock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "addlock", "emacs" ) provider.lock_package(["emacs"], [nil]) end it "should run zypper addlock without gpg checks" do shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks addlock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "addlock", "emacs" ) provider.lock_package(["emacs"], [nil]) end @@ -267,14 +267,14 @@ describe Chef::Provider::Package::Zypper do it "should run zypper removelock with the package name" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) shell_out_expectation!( - "zypper --non-interactive removelock emacs" + "zypper", "--non-interactive", "removelock", "emacs" ) provider.unlock_package(["emacs"], [nil]) end it "should run zypper removelock without gpg checks" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks removelock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "removelock", "emacs" ) provider.unlock_package(["emacs"], [nil]) end @@ -283,13 +283,13 @@ describe Chef::Provider::Package::Zypper do /All packages will be installed without gpg signature checks/ ) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks removelock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "removelock", "emacs" ) provider.unlock_package(["emacs"], [nil]) end it "should run zypper removelock without gpg checks" do shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks removelock emacs" + "zypper", "--non-interactive", "--no-gpg-checks", "removelock", "emacs" ) provider.unlock_package(["emacs"], [nil]) end @@ -303,7 +303,7 @@ describe Chef::Provider::Package::Zypper do describe "install_package" do it "should run zypper install with the package name and version" do shell_out_expectation!( - "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs" + "zypper", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "-y", "emacs" ) provider.install_package(["emacs"], ["1.0"]) end @@ -312,7 +312,7 @@ describe Chef::Provider::Package::Zypper do describe "upgrade_package" do it "should run zypper update with the package name and version" do shell_out_expectation!( - "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs" + "zypper", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "-y", "emacs" ) provider.upgrade_package(["emacs"], ["1.0"]) end @@ -321,7 +321,7 @@ describe Chef::Provider::Package::Zypper do describe "remove_package" do it "should run zypper remove with the package name" do shell_out_expectation!( - "zypper --no-gpg-checks remove -y emacs" + "zypper", "--no-gpg-checks", "remove", "-y", "emacs" ) provider.remove_package(["emacs"], ["1.0"]) end @@ -332,7 +332,7 @@ describe Chef::Provider::Package::Zypper do it "should install an array of package names and versions" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0 vim=2.0" + "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0", "vim=2.0" ) provider.install_package(%w{emacs vim}, ["1.0", "2.0"]) end @@ -340,7 +340,7 @@ describe Chef::Provider::Package::Zypper do it "should remove an array of package names and versions" do allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) shell_out_expectation!( - "zypper --non-interactive --no-gpg-checks remove emacs=1.0 vim=2.0" + "zypper", "--non-interactive", "--no-gpg-checks", "remove", "emacs=1.0", "vim=2.0" ) provider.remove_package(%w{emacs vim}, ["1.0", "2.0"]) end diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 27d28c698c..122e58efb7 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -517,6 +517,10 @@ describe "Subclass with use_multipackage_api" do end context "#a_to_s utility for subclasses" do + before(:each) do + Chef::Config[:treat_deprecation_warnings_as_errors] = false + end + it "converts varargs of strings to a single string" do expect(provider.send(:a_to_s, "a", nil, "b", "", "c", " ", "d e", "f-g")).to eq("a b c d e f-g") end @@ -906,6 +910,10 @@ describe "Chef::Provider::Package - Multi" do end describe "shell_out helpers" do + before(:each) do + Chef::Config[:treat_deprecation_warnings_as_errors] = false + end + [ :shell_out_with_timeout, :shell_out_with_timeout! ].each do |method| stubbed_method = method == :shell_out_with_timeout! ? :shell_out! : :shell_out [ %w{command arg1 arg2}, "command arg1 arg2" ].each do |command| diff --git a/spec/unit/resource/freebsd_package_spec.rb b/spec/unit/resource/freebsd_package_spec.rb index 4edc3dbc78..ce4300497e 100644 --- a/spec/unit/resource/freebsd_package_spec.rb +++ b/spec/unit/resource/freebsd_package_spec.rb @@ -65,7 +65,7 @@ describe Chef::Resource::FreebsdPackage do describe "if pkgng enabled" do it "should be Freebsd::Pkgng" do pkg_enabled = OpenStruct.new(:stdout => "yes\n") - allow(@resource).to receive(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) + allow(@resource).to receive(:shell_out!).with("make", "-V", "WITH_PKGNG", :env => nil).and_return(pkg_enabled) @resource.after_created expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Pkgng) end @@ -74,7 +74,7 @@ describe Chef::Resource::FreebsdPackage do describe "if freebsd_version is less than 1000017 and pkgng not enabled" do it "should be Freebsd::Pkg" do pkg_enabled = OpenStruct.new(:stdout => "\n") - allow(@resource).to receive(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) + allow(@resource).to receive(:shell_out!).with("make", "-V", "WITH_PKGNG", :env => nil).and_return(pkg_enabled) [1000016, 1000000, 901503, 902506, 802511].each do |freebsd_version| @node.automatic_attrs[:os_version] = freebsd_version diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb index dbd76d2eba..7ec3c198e4 100644 --- a/spec/unit/resource/package_spec.rb +++ b/spec/unit/resource/package_spec.rb @@ -80,6 +80,11 @@ describe Chef::Resource::Package do it "returns the file path as its identity" do expect(@resource.identity).to eq("tomcat") end + + it "takes options as an array" do + @resource.options [ "-a", "-l" ] + expect(@resource.options).to eq(["-a", "-l" ]) + end end # String, Integer |