summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorDavin Taddeo <davin@chef.io>2020-07-15 14:09:15 -0400
committerDavin Taddeo <davin@chef.io>2020-07-15 14:09:15 -0400
commit9bdf2b344af5b98905f8bc5b4744cc9d2830b08d (patch)
tree126962b91215a5cab72c1e4394050e1b87b7a748 /spec/unit
parent90c9c18ae56baa10daf77dcd4f52846657a7e38f (diff)
parent885e007cfc4381ac4a22f988e154ed2325636366 (diff)
downloadchef-9bdf2b344af5b98905f8bc5b4744cc9d2830b08d.tar.gz
Merge branch 'master' of github.com:chef/chef into windows_firewall_profile
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/chef_fs/file_system/operation_failed_error_spec.rb6
-rw-r--r--spec/unit/cookbook/gem_installer_spec.rb3
-rw-r--r--spec/unit/mixin/securable_spec.rb1
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb15
-rw-r--r--spec/unit/provider/service/windows_spec.rb8
-rw-r--r--spec/unit/resource/execute_spec.rb10
6 files changed, 21 insertions, 22 deletions
diff --git a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb
index b34d102068..101a002003 100644
--- a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb
+++ b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb
@@ -25,11 +25,9 @@ describe Chef::ChefFS::FileSystem::OperationFailedError do
context "has a cause attribute and HTTP result code is 400" do
it "include error cause" do
- allow_message_expectations_on_nil
response_body = '{"error":["Invalid key test in request body"]}'
- allow(@response).to receive(:code).and_return("400")
- allow(@response).to receive(:body).and_return(response_body)
- exception = Net::HTTPClientException.new("(exception) unauthorized", @response)
+ response = double(:response, code: "400", body: response_body)
+ exception = Net::HTTPClientException.new("(exception) unauthorized", response)
expect do
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, exception), error_message
end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}")
diff --git a/spec/unit/cookbook/gem_installer_spec.rb b/spec/unit/cookbook/gem_installer_spec.rb
index 2733dfc862..58843ac826 100644
--- a/spec/unit/cookbook/gem_installer_spec.rb
+++ b/spec/unit/cookbook/gem_installer_spec.rb
@@ -95,7 +95,8 @@ describe Chef::Cookbook::GemInstaller do
it "skip metadata installation when Chef::Config[:skip_gem_metadata_installation] is set to true" do
Chef::Config[:skip_gem_metadata_installation] = true
- expect(gem_installer.install).to_not receive(:shell_out!)
+ expect(gem_installer).to_not receive(:shell_out!)
+ expect(gem_installer.install).to be_nil
end
it "install metadata when Chef::Config[:skip_gem_metadata_installation] is not true" do
diff --git a/spec/unit/mixin/securable_spec.rb b/spec/unit/mixin/securable_spec.rb
index 538241551a..4863693dba 100644
--- a/spec/unit/mixin/securable_spec.rb
+++ b/spec/unit/mixin/securable_spec.rb
@@ -1,4 +1,3 @@
-# encoding: UTF-8
#
# Author:: Mark Mzyk (<mmzyk@chef.io>)
# Copyright:: Copyright (c) Chef Software Inc.
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 0a55ffd784..d2b2a66027 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -106,30 +106,25 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do
context "new default rubygems behavior" do
before do
Chef::Config[:rubygems_cache_enabled] = false
+
+ dep_installer = Gem::DependencyInstaller.new
+ expect(dep_installer).not_to receive(:find_gems_with_sources)
+ allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer)
end
it "finds a matching gem candidate version on rubygems 2.0.0+" do
dep = Gem::Dependency.new("rspec", ">= 0")
- dep_installer = Gem::DependencyInstaller.new
- allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer)
- expect(dep_installer).not_to receive(:find_gems_with_sources).with(dep).and_call_original
expect(@gem_env.candidate_version_from_remote(dep)).to be_kind_of(Gem::Version)
end
it "gives the candidate version as nil if none is found" do
dep = Gem::Dependency.new("lksdjflksdjflsdkfj", ">= 0")
- dep_installer = Gem::DependencyInstaller.new
- allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer)
- expect(dep_installer).not_to receive(:find_gems_with_sources).with(dep).and_call_original
expect(@gem_env.candidate_version_from_remote(dep)).to be_nil
end
it "finds a matching gem from a specific gemserver when explicit sources are given (to a server that doesn't respond to api requests)" do
dep = Gem::Dependency.new("rspec", ">= 0")
- dep_installer = Gem::DependencyInstaller.new
- allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer)
- expect(dep_installer).not_to receive(:find_gems_with_sources).with(dep).and_call_original
- expect(@gem_env.candidate_version_from_remote(dep, "http://production.cf.rubygems.org")).to be_kind_of(Gem::Version)
+ expect(@gem_env.candidate_version_from_remote(dep, "https://rubygems.org")).to be_kind_of(Gem::Version)
end
end
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb
index 9b52d93a32..b3a85715a8 100644
--- a/spec/unit/provider/service/windows_spec.rb
+++ b/spec/unit/provider/service/windows_spec.rb
@@ -22,12 +22,8 @@ require "spec_helper"
describe Chef::Provider::Service::Windows, "load_current_resource" do
include_context "Win32"
- before(:all) do
- Chef::ReservedNames::Win32::Security = Class.new unless windows?
- end
-
- after(:all) do
- Chef::ReservedNames::Win32.send(:remove_const, :Security) unless windows?
+ before do
+ stub_const("Chef::ReservedNames::Win32::Security", Class.new) unless windows?
end
let(:logger) { double("Mixlib::Log::Child").as_null_object }
diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb
index 6c61beff34..0ce29da965 100644
--- a/spec/unit/resource/execute_spec.rb
+++ b/spec/unit/resource/execute_spec.rb
@@ -63,6 +63,16 @@ describe Chef::Resource::Execute do
expect(identity[:user]).to eq("user")
end
end
+
+ context "when username is passed as an integer" do
+ let(:username) { 499 }
+
+ it "correctly parses the user and domain" do
+ identity = resource.qualify_user(username, password, domain)
+ expect(identity[:domain]).to eq(nil)
+ expect(identity[:user]).to eq(499)
+ end
+ end
end
shared_examples_for "it received valid credentials" do