diff options
Diffstat (limited to 'spec/unit/provider/package_spec.rb')
-rw-r--r-- | spec/unit/provider/package_spec.rb | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 375a0d0646..3a42bcacf6 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -34,80 +34,80 @@ describe Chef::Provider::Package do describe "when installing a package" do before(:each) do @provider.current_resource = @current_resource - @provider.stub(:install_package).and_return(true) + allow(@provider).to receive(:install_package).and_return(true) end it "should raise a Chef::Exceptions::Package if no version is specified, and no candidate is available" do @provider.candidate_version = nil - 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 call preseed_package if a response_file is given" do @new_resource.response_file("foo") - @provider.should_receive(:get_preseed_file).with( + expect(@provider).to receive(:get_preseed_file).with( @new_resource.name, @provider.candidate_version ).and_return("/var/cache/preseed-test") - @provider.should_receive(:preseed_package).with( + expect(@provider).to receive(:preseed_package).with( "/var/cache/preseed-test" ).and_return(true) @provider.run_action(:install) end it "should not call preseed_package if a response_file is not given" do - @provider.should_not_receive(:preseed_package) + expect(@provider).not_to receive(:preseed_package) @provider.run_action(:install) end it "should install the package at the candidate_version if it is not already installed" do - @provider.should_receive(:install_package).with( + expect(@provider).to receive(:install_package).with( @new_resource.name, @provider.candidate_version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should install the package at the version specified if it is not already installed" do @new_resource.version("1.0") - @provider.should_receive(:install_package).with( + expect(@provider).to receive(:install_package).with( @new_resource.name, @new_resource.version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should install the package at the version specified if a different version is installed" do @new_resource.version("1.0") - @current_resource.stub(:version).and_return("0.99") - @provider.should_receive(:install_package).with( + allow(@current_resource).to receive(:version).and_return("0.99") + expect(@provider).to receive(:install_package).with( @new_resource.name, @new_resource.version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not install the package if it is already installed and no version is specified" do @current_resource.version("1.0") - @provider.should_not_receive(:install_package) + expect(@provider).not_to receive(:install_package) @provider.run_action(:install) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should not install the package if it is already installed at the version specified" do @current_resource.version("1.0") @new_resource.version("1.0") - @provider.should_not_receive(:install_package) + expect(@provider).not_to receive(:install_package) @provider.run_action(:install) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should call the candidate_version accessor only once if the package is already installed and no version is specified" do @current_resource.version("1.0") - @provider.stub(:candidate_version).and_return("1.0") + allow(@provider).to receive(:candidate_version).and_return("1.0") @provider.run_action(:install) end @@ -119,220 +119,220 @@ describe Chef::Provider::Package do it "should set the resource to updated if it installs the package" do @provider.run_action(:install) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "when upgrading the package" do before(:each) do - @provider.stub(:upgrade_package).and_return(true) + allow(@provider).to receive(:upgrade_package).and_return(true) end it "should upgrade the package if the current version is not the candidate version" do - @provider.should_receive(:upgrade_package).with( + expect(@provider).to receive(:upgrade_package).with( @new_resource.name, @provider.candidate_version ).and_return(true) @provider.run_action(:upgrade) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should set the resource to updated if it installs the package" do @provider.run_action(:upgrade) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not install the package if the current version is the candidate version" do @current_resource.version "1.0" - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.run_action(:upgrade) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should print the word 'uninstalled' if there was no original version" do - @current_resource.stub(:version).and_return(nil) - Chef::Log.should_receive(:info).with("package[emacs] upgraded from uninstalled to 1.0") + allow(@current_resource).to receive(:version).and_return(nil) + expect(Chef::Log).to receive(:info).with("package[emacs] upgraded from uninstalled to 1.0") @provider.run_action(:upgrade) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should raise a Chef::Exceptions::Package if current version and candidate are nil" do - @current_resource.stub(:version).and_return(nil) + allow(@current_resource).to receive(:version).and_return(nil) @provider.candidate_version = nil - lambda { @provider.run_action(:upgrade) }.should raise_error(Chef::Exceptions::Package) + expect { @provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package) end it "should not install the package if candidate version is nil" do @current_resource.version "1.0" @provider.candidate_version = nil - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.run_action(:upgrade) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end describe "When removing the package" do before(:each) do - @provider.stub(:remove_package).and_return(true) + allow(@provider).to receive(:remove_package).and_return(true) @current_resource.version '1.4.2' end it "should remove the package if it is installed" do - @provider.should be_removing_package - @provider.should_receive(:remove_package).with('emacs', nil) + expect(@provider).to be_removing_package + expect(@provider).to receive(:remove_package).with('emacs', nil) @provider.run_action(:remove) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should remove the package at a specific version if it is installed at that version" do @new_resource.version "1.4.2" - @provider.should be_removing_package - @provider.should_receive(:remove_package).with('emacs', '1.4.2') + expect(@provider).to be_removing_package + expect(@provider).to receive(:remove_package).with('emacs', '1.4.2') @provider.run_action(:remove) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not remove the package at a specific version if it is not installed at that version" do @new_resource.version "1.0" - @provider.should_not be_removing_package - @provider.should_not_receive(:remove_package) + expect(@provider).not_to be_removing_package + expect(@provider).not_to receive(:remove_package) @provider.run_action(:remove) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should not remove the package if it is not installed" do - @provider.should_not_receive(:remove_package) - @current_resource.stub(:version).and_return(nil) + expect(@provider).not_to receive(:remove_package) + allow(@current_resource).to receive(:version).and_return(nil) @provider.run_action(:remove) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should set the resource to updated if it removes the package" do @provider.run_action(:remove) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "When purging the package" do before(:each) do - @provider.stub(:purge_package).and_return(true) + allow(@provider).to receive(:purge_package).and_return(true) @current_resource.version '1.4.2' end it "should purge the package if it is installed" do - @provider.should be_removing_package - @provider.should_receive(:purge_package).with('emacs', nil) + expect(@provider).to be_removing_package + expect(@provider).to receive(:purge_package).with('emacs', nil) @provider.run_action(:purge) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should purge the package at a specific version if it is installed at that version" do @new_resource.version "1.4.2" - @provider.should be_removing_package - @provider.should_receive(:purge_package).with('emacs', '1.4.2') + expect(@provider).to be_removing_package + expect(@provider).to receive(:purge_package).with('emacs', '1.4.2') @provider.run_action(:purge) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not purge the package at a specific version if it is not installed at that version" do @new_resource.version "1.0" - @provider.should_not be_removing_package - @provider.should_not_receive(:purge_package) + expect(@provider).not_to be_removing_package + expect(@provider).not_to receive(:purge_package) @provider.run_action(:purge) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should not purge the package if it is not installed" do @current_resource.instance_variable_set(:@version, nil) - @provider.should_not be_removing_package + expect(@provider).not_to be_removing_package - @provider.should_not_receive(:purge_package) + expect(@provider).not_to receive(:purge_package) @provider.run_action(:purge) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should set the resource to updated if it purges the package" do @provider.run_action(:purge) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "when reconfiguring the package" do before(:each) do - @provider.stub(:reconfig_package).and_return(true) + allow(@provider).to receive(:reconfig_package).and_return(true) end it "should info log, reconfigure the package and update the resource" do - @current_resource.stub(:version).and_return('1.0') - @new_resource.stub(:response_file).and_return(true) - @provider.should_receive(:get_preseed_file).and_return('/var/cache/preseed-test') - @provider.stub(:preseed_package).and_return(true) - @provider.stub(:reconfig_package).and_return(true) - Chef::Log.should_receive(:info).with("package[emacs] reconfigured") - @provider.should_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(true) + expect(@provider).to receive(:get_preseed_file).and_return('/var/cache/preseed-test') + allow(@provider).to receive(:preseed_package).and_return(true) + allow(@provider).to receive(:reconfig_package).and_return(true) + expect(Chef::Log).to receive(:info).with("package[emacs] reconfigured") + expect(@provider).to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should debug log and not reconfigure the package if the package is not installed" do - @current_resource.stub(:version).and_return(nil) - Chef::Log.should_receive(:debug).with("package[emacs] is NOT installed - nothing to do") - @provider.should_not_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return(nil) + expect(Chef::Log).to receive(:debug).with("package[emacs] is NOT installed - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should debug log and not reconfigure the package if no response_file is given" do - @current_resource.stub(:version).and_return('1.0') - @new_resource.stub(:response_file).and_return(nil) - Chef::Log.should_receive(:debug).with("package[emacs] no response_file provided - nothing to do") - @provider.should_not_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(nil) + expect(Chef::Log).to receive(:debug).with("package[emacs] no response_file provided - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should debug log and not reconfigure the package if the response_file has not changed" do - @current_resource.stub(:version).and_return('1.0') - @new_resource.stub(:response_file).and_return(true) - @provider.should_receive(:get_preseed_file).and_return(false) - @provider.stub(:preseed_package).and_return(false) - Chef::Log.should_receive(:debug).with("package[emacs] preseeding has not changed - nothing to do") - @provider.should_not_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(true) + expect(@provider).to receive(:get_preseed_file).and_return(false) + allow(@provider).to receive(:preseed_package).and_return(false) + expect(Chef::Log).to receive(:debug).with("package[emacs] preseeding has not changed - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end describe "when running commands to be implemented by subclasses" do it "should raises UnsupportedAction for install" do - lambda { @provider.install_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.install_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for upgrade" do - lambda { @provider.upgrade_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.upgrade_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for remove" do - lambda { @provider.remove_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.remove_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for purge" do - lambda { @provider.purge_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.purge_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raise UnsupportedAction for preseed_package" do preseed_file = "/tmp/sun-jdk-package-preseed-file.seed" - lambda { @provider.preseed_package(preseed_file) }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.preseed_package(preseed_file) }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raise UnsupportedAction for reconfig" do - lambda { @provider.reconfig_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.reconfig_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end end @@ -358,29 +358,29 @@ describe Chef::Provider::Package do describe "creating the cookbook file resource to fetch the response file" do before do - Chef::FileCache.should_receive(:create_cache_path).with('preseed/java').and_return("/tmp/preseed/java") + expect(Chef::FileCache).to receive(:create_cache_path).with('preseed/java').and_return("/tmp/preseed/java") end it "sets the preseed resource's runcontext to its own run context" do - Chef::FileCache.stub(:create_cache_path).and_return("/tmp/preseed/java") - @provider.preseed_resource('java', '6').run_context.should_not be_nil - @provider.preseed_resource('java', '6').run_context.should equal(@provider.run_context) + allow(Chef::FileCache).to receive(:create_cache_path).and_return("/tmp/preseed/java") + expect(@provider.preseed_resource('java', '6').run_context).not_to be_nil + expect(@provider.preseed_resource('java', '6').run_context).to equal(@provider.run_context) end it "should set the cookbook name of the remote file to the new resources cookbook name" do - @provider.preseed_resource('java', '6').cookbook_name.should == 'java' + expect(@provider.preseed_resource('java', '6').cookbook_name).to eq('java') end it "should set remote files source to the new resources response file" do - @provider.preseed_resource('java', '6').source.should == 'java.response' + expect(@provider.preseed_resource('java', '6').source).to eq('java.response') end it "should never back up the cached response file" do - @provider.preseed_resource('java', '6').backup.should be_false + expect(@provider.preseed_resource('java', '6').backup).to be_false end it "sets the install path of the resource to $file_cache/$cookbook/$pkg_name-$pkg_version.seed" do - @provider.preseed_resource('java', '6').path.should == '/tmp/preseed/java/java-6.seed' + expect(@provider.preseed_resource('java', '6').path).to eq('/tmp/preseed/java/java-6.seed') end end @@ -397,7 +397,7 @@ describe Chef::Provider::Package do @response_file_resource.source('java.response') - @provider.should_receive(:preseed_resource).with('java', '6').and_return(@response_file_resource) + expect(@provider).to receive(:preseed_resource).with('java', '6').and_return(@response_file_resource) end after do @@ -405,20 +405,20 @@ describe Chef::Provider::Package do end it "creates the preseed file in the cache" do - @response_file_resource.should_receive(:run_action).with(:create) + expect(@response_file_resource).to receive(:run_action).with(:create) @provider.get_preseed_file("java", "6") end it "returns the path to the response file if the response file was updated" do - @provider.get_preseed_file("java", "6").should == @response_file_destination + expect(@provider.get_preseed_file("java", "6")).to eq(@response_file_destination) end it "should return false if the response file has not been updated" do @response_file_resource.updated_by_last_action(false) - @response_file_resource.should_not be_updated_by_last_action + expect(@response_file_resource).not_to be_updated_by_last_action # don't let the response_file_resource set updated to true - @response_file_resource.should_receive(:run_action).with(:create) - @provider.get_preseed_file("java", "6").should be(false) + expect(@response_file_resource).to receive(:run_action).with(:create) + expect(@provider.get_preseed_file("java", "6")).to be(false) end end |