summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package/rpm_spec.rb
diff options
context:
space:
mode:
authorDavid Crowder <david.crowder@cerner.com>2014-12-29 17:26:32 -0600
committertyler-ball <tyleraball@gmail.com>2015-01-28 11:44:46 -0800
commit1129658da498dfdefb1aead453b21ecb6c2df61c (patch)
tree165494f1de1e6f31e4b6a437f915f7ea46ea7362 /spec/unit/provider/package/rpm_spec.rb
parentdb12d259b7b12194c8d5fb5e82e3245d62253e9c (diff)
downloadchef-1129658da498dfdefb1aead453b21ecb6c2df61c.tar.gz
use context in conjunction with let as opposed to local variables and require shellout explicitly in the provider
Diffstat (limited to 'spec/unit/provider/package/rpm_spec.rb')
-rw-r--r--spec/unit/provider/package/rpm_spec.rb123
1 files changed, 61 insertions, 62 deletions
diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb
index 5e3f3f9f1b..07c5dea8c6 100644
--- a/spec/unit/provider/package/rpm_spec.rb
+++ b/spec/unit/provider/package/rpm_spec.rb
@@ -19,9 +19,7 @@
require 'spec_helper'
describe Chef::Provider::Package::Rpm do
-
- subject(:provider) { Chef::Provider::Package::Rpm.new(new_resource, run_context) }
-
+ let(:provider) { Chef::Provider::Package::Rpm.new(new_resource, run_context) }
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let(:run_context) { Chef::RunContext.new(node, {}, events) }
@@ -33,22 +31,19 @@ describe Chef::Provider::Package::Rpm do
let(:exitstatus) { 0 }
let(:stdout) { String.new('') }
let(:status) { double('Process::Status', exitstatus: exitstatus, stdout: stdout) }
- let(:exitstatus) { 0 }
before(:each) do
allow(::File).to receive(:exists?).and_return(true)
+ allow(provider).to receive(:shell_out!).and_return(status)
end
describe "when determining the current state of the package" do
-
it "should create a current resource with the name of new_resource" do
- allow(provider).to receive(:shell_out!).and_return(status)
provider.load_current_resource
expect(provider.current_resource.name).to eq("ImageMagick-c++")
end
it "should set the current reource package name to the new resource package name" do
- allow(provider).to receive(:shell_out!).and_return(status)
provider.load_current_resource
expect(provider.current_resource.package_name).to eq('ImageMagick-c++')
end
@@ -58,52 +53,57 @@ describe Chef::Provider::Package::Rpm do
expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
end
- it "should get the source package version from rpm if provided" do
- stdout = "ImageMagick-c++ 6.5.4.7-7.el6_5"
- status = double("Status", :exitstatus => 0, :stdout => stdout)
- expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(status)
- expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(status)
- provider.load_current_resource
- expect(provider.current_resource.package_name).to eq("ImageMagick-c++")
- expect(provider.new_resource.version).to eq("6.5.4.7-7.el6_5")
- end
+ context "installation exists" do
+ let(:stdout) { "ImageMagick-c++ 6.5.4.7-7.el6_5" }
- it "should return the current version installed if found by rpm" do
- stdout = "ImageMagick-c++ 6.5.4.7-7.el6_5"
- status = double("Status", :exitstatus => 0, :stdout => stdout)
- expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(status)
- expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(status)
- provider.load_current_resource
- expect(provider.current_resource.version).to eq("6.5.4.7-7.el6_5")
- end
+ it "should get the source package version from rpm if provided" do
+ expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(status)
+ expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(status)
+ provider.load_current_resource
+ expect(provider.current_resource.package_name).to eq("ImageMagick-c++")
+ expect(provider.new_resource.version).to eq("6.5.4.7-7.el6_5")
+ end
- it "should raise an exception if the source is not set but we are installing" do
- new_resource = Chef::Resource::Package.new("ImageMagick-c++")
- provider = Chef::Provider::Package::Rpm.new(new_resource, run_context)
- expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
+ it "should return the current version installed if found by rpm" do
+ expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(status)
+ expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(status)
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eq("6.5.4.7-7.el6_5")
+ end
end
- it "should raise an exception if rpm fails to run" do
- status = double("Status", :exitstatus => -1, :stdout => stdout)
- allow(provider).to receive(:shell_out!).and_return(status)
- expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
+ context "source is not defiend" do
+ let(:new_resource) { Chef::Resource::Package.new("ImageMagick-c++") }
+
+ it "should raise an exception if the source is not set but we are installing" do
+ expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
+ end
end
- it "should not detect the package name as version when not installed" do
- stdout = "package openssh-askpass is not installed"
- status = double("Status", :exitstatus => -1, :stdout => stdout)
- new_resource = Chef::Resource::Package.new("openssh-askpass")
- new_resource.source 'openssh-askpass'
- provider = Chef::Provider::Package::Rpm.new(new_resource, run_context)
- expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(status)
- expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(status)
- provider.load_current_resource
- expect(provider.current_resource.version).to be_nil
+ context "installation does not exist" do
+ let(:stdout) { String.new("package openssh-askpass is not installed") }
+ let(:exitstatus) { -1 }
+ let(:new_resource) do
+ Chef::Resource::Package.new("openssh-askpass").tap do |resource|
+ resource.source "openssh-askpass"
+ end
+ end
+
+ it "should raise an exception if rpm fails to run" do
+ allow(provider).to receive(:shell_out!).and_return(status)
+ expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "should not detect the package name as version when not installed" do
+ expect(provider).to receive(:shell_out!).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(status)
+ expect(provider).to receive(:shell_out!).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(status)
+ provider.load_current_resource
+ expect(provider.current_resource.version).to be_nil
+ end
end
end
describe "after the current resource is loaded" do
-
let(:current_resource) { Chef::Resource::Package.new("ImageMagick-c++") }
let(:provider) do
Chef::Provider::Package::Rpm.new(new_resource, run_context).tap do |provider|
@@ -129,25 +129,24 @@ describe Chef::Provider::Package::Rpm do
provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5")
end
- it "should install from a path when the package is a path and the source is nil" do
- new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
- provider = Chef::Provider::Package::Rpm.new(new_resource, run_context)
- expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
- current_resource = Chef::Resource::Package.new("ImageMagick-c++")
- 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")
- provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
- end
-
- it "should uprgrade from a path when the package is a path and the source is nil" do
- new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
- provider = Chef::Provider::Package::Rpm.new(new_resource, run_context)
- expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
- current_resource = Chef::Resource::Package.new("ImageMagick-c++")
- 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")
- provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
+ context "installing when the name is a path" do
+ let(:new_resource) { Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") }
+ let(:current_resource) { Chef::Resource::Package.new("ImageMagick-c++") }
+
+ 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")
+ provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
+ end
+
+ it "should uprgrade 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")
+ 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")
+ 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
it "installs with custom options specified in the resource" do