summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2016-02-24 14:50:30 -0800
committerChris Doherty <cdoherty@chef.io>2016-02-25 15:51:20 -0800
commit588a0a63590631e40e364d7eb1918d9461c7801c (patch)
treecb3b6ae4e49835c87471bde85137a23c1a0b12c9
parent768ca5bcb0e5074528f9cd41d303590256b89ec6 (diff)
downloadchef-588a0a63590631e40e364d7eb1918d9461c7801c.tar.gz
Add a spec to better mimic the acceptance test.
-rw-r--r--lib/chef/provider/package/chocolatey.rb12
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb15
2 files changed, 19 insertions, 8 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 1d660f2cfd..96ec8c0a8c 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -150,12 +150,12 @@ EOS
@choco_exe ||=
# if this check is in #define_resource_requirements, it won't get
# run before choco.exe gets called from #load_current_resource.
- exe_path = ::File.join(choco_install_path, "bin", "choco.exe")
- if !::File.exists?(exe_path.to_s)
- raise Chef::Exceptions::MissingLibrary, CHOCO_MISSING_MSG
- else
- exe_path
- end
+ exe_path = ::File.join(choco_install_path.to_s, "bin", "choco.exe")
+ if !::File.exist?(exe_path)
+ raise Chef::Exceptions::MissingLibrary, CHOCO_MISSING_MSG
+ else
+ exe_path
+ end
end
# lets us mock out an incorrect value for testing.
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
index 02414a3a96..8a69cf3da4 100644
--- a/spec/unit/provider/package/chocolatey_spec.rb
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -475,16 +475,27 @@ describe "behavior when Chocolatey is not installed" do
end
before {
- allow(provider).to receive(:choco_install_path).and_return("")
+ # the shellout sometimes returns "", but test nil to be safe.
+ allow(provider).to receive(:choco_install_path).and_return(nil)
provider.instance_variable_set("@choco_install_path", nil)
# we don't care what this returns, but we have to let it be called.
allow(provider).to receive(:shell_out!).and_return(double(:stdout => ""))
}
+ let(:error_regex) {
+ /Could not locate.*install.*cookbook.*PowerShell.*GetEnvironmentVariable/m
+ }
+
context "#choco_exe" do
it "triggers a MissingLibrary exception when Chocolatey is not installed" do
- expect { provider.send(:choco_exe) }.to raise_error(Chef::Exceptions::MissingLibrary, /Could not locate.*install.*cookbook.*PowerShell.*GetEnvironmentVariable/m)
+ expect { provider.send(:choco_exe) }.to raise_error(Chef::Exceptions::MissingLibrary, error_regex)
+ end
+ end
+
+ context "#load_current_resource" do
+ it "triggers a MissingLibrary exception when Chocolatey is not installed" do
+ expect { provider.load_current_resource }.to raise_error(Chef::Exceptions::MissingLibrary, error_regex)
end
end
end