From bd0b0a34e4dbb60fe61bbc8716df90e8f7c7d19a Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 24 Oct 2014 18:12:50 -0700 Subject: updating resources/providers unit tests to rpsec3 mechanically generated patch using transpec 2.3.7 gem --- spec/unit/provider/package/dpkg_spec.rb | 54 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'spec/unit/provider/package/dpkg_spec.rb') diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 439a42daa3..fdd9e50c8e 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -33,32 +33,32 @@ describe Chef::Provider::Package::Dpkg do @status = double("Status", :exitstatus => 0) @stderr = StringIO.new @pid = double("PID") - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) - ::File.stub(:exists?).and_return(true) + allow(::File).to receive(:exists?).and_return(true) end describe "when loading the current resource state" do it "should create a current resource with the name of the new_resource" do @provider.load_current_resource - @provider.current_resource.package_name.should == "wget" + expect(@provider.current_resource.package_name).to eq("wget") end it "should raise an exception if a source is supplied but not found" do @provider.load_current_resource @provider.define_resource_requirements - ::File.stub(:exists?).and_return(false) - lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) + allow(::File).to receive(:exists?).and_return(false) + expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end describe 'gets the source package version from dpkg-deb' do def check_version(version) @stdout = StringIO.new("wget\t#{version}") - @provider.stub(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "wget" - @new_resource.version.should == version + expect(@provider.current_resource.package_name).to eq("wget") + expect(@new_resource.version).to eq(version) end it 'if short version provided' do @@ -80,9 +80,9 @@ describe Chef::Provider::Package::Dpkg do it "gets the source package name from dpkg-deb correctly when the package name has `-', `+' or `.' characters" do @stdout = StringIO.new("f.o.o-pkg++2\t1.11.4-1ubuntu1") - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "f.o.o-pkg++2" + expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2") end it "should raise an exception if the source is not set but we are installing" do @@ -90,7 +90,7 @@ describe Chef::Provider::Package::Dpkg do @provider.new_resource = @new_resource @provider.define_resource_requirements @provider.load_current_resource - lambda { @provider.run_action(:install)}.should raise_error(Chef::Exceptions::Package) + expect { @provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package) end it "should return the current version installed if found by dpkg" do @@ -107,22 +107,22 @@ Config-Version: 1.11.4-1ubuntu1 Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5) Conflicts: wget-ssl DPKG_S - @provider.stub(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should == "1.11.4-1ubuntu1" + expect(@provider.current_resource.version).to eq("1.11.4-1ubuntu1") end it "should raise an exception if dpkg fails to run" do @status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end end describe Chef::Provider::Package::Dpkg, "install and upgrade" do it "should run dpkg -i with the package source" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.install_package("wget", "1.11.4-1ubuntu1") @@ -131,7 +131,7 @@ DPKG_S it "should run dpkg -i if the package is a path and the source is nil" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") @@ -140,55 +140,55 @@ DPKG_S it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") end it "should run dpkg -i with the package source and options if specified" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(:options).and_return("--force-yes") @provider.install_package("wget", "1.11.4-1ubuntu1") end it "should upgrade by running install_package" do - @provider.should_receive(:install_package).with("wget", "1.11.4-1ubuntu1") + expect(@provider).to receive(:install_package).with("wget", "1.11.4-1ubuntu1") @provider.upgrade_package("wget", "1.11.4-1ubuntu1") end end describe Chef::Provider::Package::Dpkg, "remove and purge" do it "should run dpkg -r to remove the package" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "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 - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -r --force-yes wget" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(:options).and_return("--force-yes") @provider.remove_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -P to purge the package" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "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 - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -P --force-yes wget" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(:options).and_return("--force-yes") @provider.purge_package("wget", "1.11.4-1ubuntu1") end -- cgit v1.2.1