summaryrefslogtreecommitdiff
path: root/spec/support/shared/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared/unit')
-rw-r--r--spec/support/shared/unit/api_versioning.rb6
-rw-r--r--spec/support/shared/unit/execute_resource.rb2
-rw-r--r--spec/support/shared/unit/file_system_support.rb10
-rw-r--r--spec/support/shared/unit/platform_introspector.rb54
-rw-r--r--spec/support/shared/unit/provider/file.rb18
-rw-r--r--spec/support/shared/unit/provider/useradd_based_user_provider.rb48
-rw-r--r--spec/support/shared/unit/script_resource.rb12
-rw-r--r--spec/support/shared/unit/windows_script_resource.rb8
8 files changed, 79 insertions, 79 deletions
diff --git a/spec/support/shared/unit/api_versioning.rb b/spec/support/shared/unit/api_versioning.rb
index ccbe95d029..261efc6f52 100644
--- a/spec/support/shared/unit/api_versioning.rb
+++ b/spec/support/shared/unit/api_versioning.rb
@@ -19,7 +19,7 @@
require "chef/exceptions"
shared_examples_for "version handling" do
- let(:response_406) { OpenStruct.new(:code => '406') }
+ let(:response_406) { OpenStruct.new(:code => "406") }
let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
before do
@@ -38,7 +38,7 @@ shared_examples_for "version handling" do
end # version handling
shared_examples_for "user and client reregister" do
- let(:response_406) { OpenStruct.new(:code => '406') }
+ let(:response_406) { OpenStruct.new(:code => "406") }
let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) }
let(:generic_exception) { Exception.new }
let(:min_version) { "2" }
@@ -55,7 +55,7 @@ shared_examples_for "user and client reregister" do
context "when the exception is 406 and returns x-ops-server-api-version header" do
before do
allow(rest_v0).to receive(:put).and_raise(exception_406)
- allow(response_406).to receive(:[]).with('x-ops-server-api-version').and_return(Chef::JSONCompat.to_json(return_hash_406))
+ allow(response_406).to receive(:[]).with("x-ops-server-api-version").and_return(Chef::JSONCompat.to_json(return_hash_406))
end
it "raises an error about only V0 being supported" do
diff --git a/spec/support/shared/unit/execute_resource.rb b/spec/support/shared/unit/execute_resource.rb
index 3a88ff8890..e5bcbd5e91 100644
--- a/spec/support/shared/unit/execute_resource.rb
+++ b/spec/support/shared/unit/execute_resource.rb
@@ -17,7 +17,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
shared_examples_for "an execute resource" do
diff --git a/spec/support/shared/unit/file_system_support.rb b/spec/support/shared/unit/file_system_support.rb
index 3aee46fc7f..f071cffee3 100644
--- a/spec/support/shared/unit/file_system_support.rb
+++ b/spec/support/shared/unit/file_system_support.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'chef/chef_fs/file_system'
-require 'chef/chef_fs/file_system/memory/memory_root'
-require 'chef/chef_fs/file_system/memory/memory_dir'
-require 'chef/chef_fs/file_system/memory/memory_file'
+require "chef/chef_fs/file_system"
+require "chef/chef_fs/file_system/memory/memory_root"
+require "chef/chef_fs/file_system/memory/memory_dir"
+require "chef/chef_fs/file_system/memory/memory_file"
module FileSystemSupport
def memory_fs(pretty_name, value, cannot_be_in_regex = nil)
@@ -33,7 +33,7 @@ module FileSystemSupport
dir
end
- def memory_fs_value(value, name = '', parent = nil)
+ def memory_fs_value(value, name = "", parent = nil)
if value.is_a?(Hash)
dir = Chef::ChefFS::FileSystem::Memory::MemoryDir.new(name, parent)
value.each do |key, child|
diff --git a/spec/support/shared/unit/platform_introspector.rb b/spec/support/shared/unit/platform_introspector.rb
index 52a780eb10..51a2befdbb 100644
--- a/spec/support/shared/unit/platform_introspector.rb
+++ b/spec/support/shared/unit/platform_introspector.rb
@@ -30,10 +30,10 @@ shared_examples_for "a platform introspector" do
@platform_hash["debian"] = {["5", "6"] => "debian-5/6", "default" => "debian"}
@platform_hash["default"] = "default"
# The following @platform_hash keys are used for testing version constraints
- @platform_hash['exact_match'] = { '1.2.3' => 'exact', '>= 1.0' => 'not exact'}
- @platform_hash['multiple_matches'] = { '~> 2.3.4' => 'matched ~> 2.3.4', '>= 2.3' => 'matched >=2.3' }
- @platform_hash['invalid_cookbook_version'] = {'>= 21' => 'Matches a single number'}
- @platform_hash['successful_matches'] = { '< 3.0' => 'matched < 3.0', '>= 3.0' => 'matched >= 3.0' }
+ @platform_hash["exact_match"] = { "1.2.3" => "exact", ">= 1.0" => "not exact"}
+ @platform_hash["multiple_matches"] = { "~> 2.3.4" => "matched ~> 2.3.4", ">= 2.3" => "matched >=2.3" }
+ @platform_hash["invalid_cookbook_version"] = {">= 21" => "Matches a single number"}
+ @platform_hash["successful_matches"] = { "< 3.0" => "matched < 3.0", ">= 3.0" => "matched >= 3.0" }
@platform_family_hash = {
"debian" => "debian value",
@@ -84,28 +84,28 @@ shared_examples_for "a platform introspector" do
expect(platform_introspector.value_for_platform(@platform_hash)).to eq("openbsd")
end
- it 'returns the exact match' do
- node.automatic_attrs[:platform] = 'exact_match'
- node.automatic_attrs[:platform_version] = '1.2.3'
- expect(platform_introspector.value_for_platform(@platform_hash)).to eq('exact')
+ it "returns the exact match" do
+ node.automatic_attrs[:platform] = "exact_match"
+ node.automatic_attrs[:platform_version] = "1.2.3"
+ expect(platform_introspector.value_for_platform(@platform_hash)).to eq("exact")
end
- it 'raises RuntimeError' do
- node.automatic_attrs[:platform] = 'multiple_matches'
- node.automatic_attrs[:platform_version] = '2.3.4'
+ it "raises RuntimeError" do
+ node.automatic_attrs[:platform] = "multiple_matches"
+ node.automatic_attrs[:platform_version] = "2.3.4"
expect {platform_introspector.value_for_platform(@platform_hash)}.to raise_error(RuntimeError)
end
- it 'should not require .0 to match >= 21.0' do
- node.automatic_attrs[:platform] = 'invalid_cookbook_version'
- node.automatic_attrs[:platform_version] = '21'
- expect(platform_introspector.value_for_platform(@platform_hash)).to eq('Matches a single number')
+ it "should not require .0 to match >= 21.0" do
+ node.automatic_attrs[:platform] = "invalid_cookbook_version"
+ node.automatic_attrs[:platform_version] = "21"
+ expect(platform_introspector.value_for_platform(@platform_hash)).to eq("Matches a single number")
end
- it 'should return the value for that match' do
- node.automatic_attrs[:platform] = 'successful_matches'
- node.automatic_attrs[:platform_version] = '2.9'
- expect(platform_introspector.value_for_platform(@platform_hash)).to eq('matched < 3.0')
+ it "should return the value for that match" do
+ node.automatic_attrs[:platform] = "successful_matches"
+ node.automatic_attrs[:platform_version] = "2.9"
+ expect(platform_introspector.value_for_platform(@platform_hash)).to eq("matched < 3.0")
end
describe "when platform versions is an array" do
@@ -125,17 +125,17 @@ shared_examples_for "a platform introspector" do
describe "when checking platform?" do
it "returns true if the node is a provided platform and platforms are provided as symbols" do
- node.automatic_attrs[:platform] = 'ubuntu'
+ node.automatic_attrs[:platform] = "ubuntu"
expect(platform_introspector.platform?([:redhat, :ubuntu])).to eq(true)
end
it "returns true if the node is a provided platform and platforms are provided as strings" do
- node.automatic_attrs[:platform] = 'ubuntu'
+ node.automatic_attrs[:platform] = "ubuntu"
expect(platform_introspector.platform?(["redhat", "ubuntu"])).to eq(true)
end
it "returns false if the node is not of the provided platforms" do
- node.automatic_attrs[:platform] = 'ubuntu'
+ node.automatic_attrs[:platform] = "ubuntu"
expect(platform_introspector.platform?(:splatlinux)).to eq(false)
end
end
@@ -143,17 +143,17 @@ shared_examples_for "a platform introspector" do
describe "when checking platform_family?" do
it "returns true if the node is in a provided platform family and families are provided as symbols" do
- node.automatic_attrs[:platform_family] = 'debian'
+ node.automatic_attrs[:platform_family] = "debian"
expect(platform_introspector.platform_family?([:rhel, :debian])).to eq(true)
end
it "returns true if the node is a provided platform and platforms are provided as strings" do
- node.automatic_attrs[:platform_family] = 'rhel'
+ node.automatic_attrs[:platform_family] = "rhel"
expect(platform_introspector.platform_family?(["rhel", "debian"])).to eq(true)
end
it "returns false if the node is not of the provided platforms" do
- node.automatic_attrs[:platform_family] = 'suse'
+ node.automatic_attrs[:platform_family] = "suse"
expect(platform_introspector.platform_family?(:splatlinux)).to eq(false)
end
@@ -176,13 +176,13 @@ shared_examples_for "a platform introspector" do
it "returns the correct default for a given platform" do
node.automatic_attrs[:platform] = "debian"
- node.automatic_attrs[:platform_version] = '9000'
+ node.automatic_attrs[:platform_version] = "9000"
expect(platform_introspector.value_for_platform(@platform_hash)).to eq([ :restart, :reload, :status ])
end
it "returns the correct platform+version specific value " do
node.automatic_attrs[:platform] = "debian"
- node.automatic_attrs[:platform_version] = '4.0'
+ node.automatic_attrs[:platform_version] = "4.0"
expect(platform_introspector.value_for_platform(@platform_hash)).to eq([:restart, :reload])
end
end
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 973cb047f7..82260b07df 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'tmpdir'
+require "spec_helper"
+require "tmpdir"
if windows?
- require 'chef/win32/file'
+ require "chef/win32/file"
end
# Filesystem stubs
@@ -37,7 +37,7 @@ end
# forwards-vs-reverse slashes on windows sucks
def windows_path
- windows? ? normalized_path.gsub(/\\/, '/') : normalized_path
+ windows? ? normalized_path.gsub(/\\/, "/") : normalized_path
end
# this is all getting a bit stupid, CHEF-4802 cut to remove all this
@@ -460,7 +460,7 @@ shared_examples_for Chef::Provider::File do
before { setup_normal_file }
let(:tempfile) {
- t = double('Tempfile', :path => "/tmp/foo-bar-baz", :closed? => true)
+ t = double("Tempfile", :path => "/tmp/foo-bar-baz", :closed? => true)
allow(content).to receive(:tempfile).and_return(t)
t
}
@@ -507,7 +507,7 @@ shared_examples_for Chef::Provider::File do
before do
setup_normal_file
provider.load_current_resource
- tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz")
+ tempfile = double("Tempfile", :path => "/tmp/foo-bar-baz")
allow(content).to receive(:tempfile).and_return(tempfile)
expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(true)
expect(tempfile).to receive(:close).once
@@ -520,7 +520,7 @@ shared_examples_for Chef::Provider::File do
let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" }
before do
allow(provider).to receive(:contents_changed?).and_return(true)
- diff = double('Diff', :for_output => ['+++','---','+foo','-bar'],
+ diff = double("Diff", :for_output => ["+++","---","+foo","-bar"],
:for_reporting => diff_for_reporting )
allow(diff).to receive(:diff).with(resource_path, tempfile_path).and_return(true)
expect(provider).to receive(:diff).at_least(:once).and_return(diff)
@@ -584,13 +584,13 @@ shared_examples_for Chef::Provider::File do
end
it "raises an exception when the content object returns a tempfile with a nil path" do
- tempfile = double('Tempfile', :path => nil)
+ tempfile = double("Tempfile", :path => nil)
expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile)
expect{ provider.send(:do_contents_changes) }.to raise_error
end
it "raises an exception when the content object returns a tempfile that does not exist" do
- tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz")
+ tempfile = double("Tempfile", :path => "/tmp/foo-bar-baz")
expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile)
expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false)
expect{ provider.send(:do_contents_changes) }.to raise_error
diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
index 60b048975a..07fe1f772b 100644
--- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb
+++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
@@ -60,14 +60,14 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
it "should set the option for #{attribute} if the new resources #{attribute} is not nil" do
allow(@new_resource).to receive(attribute).and_return("hola")
- expect(provider.universal_options).to eql([option, 'hola'])
+ expect(provider.universal_options).to eql([option, "hola"])
end
it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management" do
allow(@new_resource).to receive(:supports).and_return({:manage_home => false,
:non_unique => false})
allow(@new_resource).to receive(attribute).and_return("hola")
- expect(provider.universal_options).to eql([option, 'hola'])
+ expect(provider.universal_options).to eql([option, "hola"])
end
it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management (using real attributes)" do
@@ -75,7 +75,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
allow(@new_resource).to receive(:non_unique).and_return(false)
allow(@new_resource).to receive(:non_unique).and_return(false)
allow(@new_resource).to receive(attribute).and_return("hola")
- expect(provider.universal_options).to eql([option, 'hola'])
+ expect(provider.universal_options).to eql([option, "hola"])
end
end
@@ -83,7 +83,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
combined_opts = []
supported_useradd_options.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option|
allow(@new_resource).to receive(attribute).and_return("hola")
- combined_opts << option << 'hola'
+ combined_opts << option << "hola"
end
expect(provider.universal_options).to eql(combined_opts)
end
@@ -156,17 +156,17 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
provider.current_resource = @current_resource
provider.new_resource.manage_home true
provider.new_resource.home "/Users/mud"
- provider.new_resource.gid '23'
+ provider.new_resource.gid "23"
end
it "runs useradd with the computed command options" do
command = ["useradd",
- "-c", 'Adam Jacob',
- "-g", '23' ]
- command.concat(["-p", 'abracadabra']) if supported_useradd_options.key?("password")
- command.concat([ "-s", '/usr/bin/zsh',
- "-u", '1000',
- "-d", '/Users/mud',
+ "-c", "Adam Jacob",
+ "-g", "23" ]
+ command.concat(["-p", "abracadabra"]) if supported_useradd_options.key?("password")
+ command.concat([ "-s", "/usr/bin/zsh",
+ "-u", "1000",
+ "-d", "/Users/mud",
"-m",
"adam" ])
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
@@ -183,11 +183,11 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
it "should not include -m or -d in the command options" do
command = ["useradd",
- "-c", 'Adam Jacob',
- "-g", '23']
- command.concat(["-p", 'abracadabra']) if supported_useradd_options.key?("password")
- command.concat([ "-s", '/usr/bin/zsh',
- "-u", '1000',
+ "-c", "Adam Jacob",
+ "-g", "23"]
+ command.concat(["-p", "abracadabra"]) if supported_useradd_options.key?("password")
+ command.concat([ "-s", "/usr/bin/zsh",
+ "-u", "1000",
"-r",
"adam" ])
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
@@ -202,15 +202,15 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
before(:each) do
provider.new_resource.manage_home true
provider.new_resource.home "/Users/mud"
- provider.new_resource.gid '23'
+ provider.new_resource.gid "23"
end
# CHEF-3423, -m must come before the username
# CHEF-4305, -d must come before -m to support CentOS/RHEL 5
it "runs usermod with the computed command options" do
command = ["usermod",
- "-g", '23',
- "-d", '/Users/mud',
+ "-g", "23",
+ "-d", "/Users/mud",
"-m",
"adam" ]
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
@@ -220,8 +220,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
it "does not set the -r option to usermod" do
@new_resource.system(true)
command = ["usermod",
- "-g", '23',
- "-d", '/Users/mud',
+ "-g", "23",
+ "-d", "/Users/mud",
"-m",
"adam" ]
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
@@ -231,7 +231,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
it "CHEF-3429: does not set -m if we aren't changing the home directory" do
expect(provider).to receive(:updating_home?).and_return(false)
command = ["usermod",
- "-g", '23',
+ "-g", "23",
"adam" ]
expect(provider).to receive(:shell_out!).with(*command).and_return(true)
provider.manage_user
@@ -307,7 +307,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
end
it "should raise a Chef::Exceptions::User if passwd -S fails on anything other than redhat/centos" do
- @node.automatic_attrs[:platform] = 'ubuntu'
+ @node.automatic_attrs[:platform] = "ubuntu"
expect(provider).to receive(:shell_out!).
with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}).
and_return(passwd_s_status)
@@ -315,7 +315,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
expect { provider.check_lock }.to raise_error(Chef::Exceptions::User)
end
- ['redhat', 'centos'].each do |os|
+ ["redhat", "centos"].each do |os|
it "should not raise a Chef::Exceptions::User if passwd -S exits with 1 on #{os} and the passwd package is version 0.73-1" do
@node.automatic_attrs[:platform] = os
expect(passwd_s_status).to receive(:exitstatus).and_return(1)
diff --git a/spec/support/shared/unit/script_resource.rb b/spec/support/shared/unit/script_resource.rb
index 18ee94606e..60967f30a3 100644
--- a/spec/support/shared/unit/script_resource.rb
+++ b/spec/support/shared/unit/script_resource.rb
@@ -17,7 +17,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
shared_examples_for "a script resource" do
@@ -49,18 +49,18 @@ shared_examples_for "a script resource" do
end
it "should raise an exception if users set command on the resource", :chef_gte_13_only do
- expect { script_resource.command('foo') }.to raise_error(Chef::Exceptions::Script)
+ expect { script_resource.command("foo") }.to raise_error(Chef::Exceptions::Script)
end
it "should not raise an exception if users set command on the resource", :chef_lt_13_only do
- expect { script_resource.command('foo') }.not_to raise_error
+ expect { script_resource.command("foo") }.not_to raise_error
end
describe "when executing guards" do
let(:resource) {
resource = script_resource
resource.run_context = run_context
- resource.code 'echo hi'
+ resource.code "echo hi"
resource
}
let(:node) {
@@ -83,7 +83,7 @@ shared_examples_for "a script resource" do
expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:evaluate_block)
expect_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).not_to receive(:evaluate_action)
expect_any_instance_of(Chef::GuardInterpreter::DefaultGuardInterpreter).to receive(:evaluate).and_return(true)
- resource.only_if 'echo hi'
+ resource.only_if "echo hi"
expect(resource.should_skip?(:run)).to eq(nil)
end
@@ -91,7 +91,7 @@ shared_examples_for "a script resource" do
expect_any_instance_of(Chef::GuardInterpreter::DefaultGuardInterpreter).not_to receive(:evaluate)
expect_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
resource.guard_interpreter :script
- resource.only_if 'echo hi'
+ resource.only_if "echo hi"
expect(resource.should_skip?(:run)).to eq(nil)
end
end
diff --git a/spec/support/shared/unit/windows_script_resource.rb b/spec/support/shared/unit/windows_script_resource.rb
index a2fc884ff2..f32cdc6e50 100644
--- a/spec/support/shared/unit/windows_script_resource.rb
+++ b/spec/support/shared/unit/windows_script_resource.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
-require 'support/shared/unit/execute_resource'
-require 'support/shared/unit/script_resource'
+require "support/shared/unit/execute_resource"
+require "support/shared/unit/script_resource"
shared_examples_for "a Windows script resource" do
before(:each) do
@@ -51,7 +51,7 @@ shared_examples_for "a Windows script resource" do
it "should use a resource to evaluate the guard when guard_interpreter is not specified" do
expect_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
expect_any_instance_of(Chef::GuardInterpreter::DefaultGuardInterpreter).not_to receive(:evaluate)
- @resource.only_if 'echo hi'
+ @resource.only_if "echo hi"
expect(@resource.should_skip?(:run)).to eq(nil)
end