summaryrefslogtreecommitdiff
path: root/spec/unit/util
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/util')
-rw-r--r--spec/unit/util/backup_spec.rb30
-rw-r--r--spec/unit/util/diff_spec.rb4
-rw-r--r--spec/unit/util/dsc/configuration_generator_spec.rb84
-rw-r--r--spec/unit/util/dsc/lcm_output_parser_spec.rb34
-rw-r--r--spec/unit/util/dsc/local_configuration_manager_spec.rb56
-rw-r--r--spec/unit/util/dsc/resource_store.rb42
-rw-r--r--spec/unit/util/editor_spec.rb130
-rw-r--r--spec/unit/util/file_edit_spec.rb6
-rw-r--r--spec/unit/util/powershell/cmdlet_spec.rb44
-rw-r--r--spec/unit/util/powershell/ps_credential_spec.rb22
-rw-r--r--spec/unit/util/selinux_spec.rb4
-rw-r--r--spec/unit/util/threaded_job_queue_spec.rb2
12 files changed, 229 insertions, 229 deletions
diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb
index f548e8241d..ab44c9fdc2 100644
--- a/spec/unit/util/backup_spec.rb
+++ b/spec/unit/util/backup_spec.rb
@@ -17,8 +17,8 @@
#
-require 'spec_helper'
-require 'tmpdir'
+require "spec_helper"
+require "tmpdir"
describe Chef::Util::Backup do
@@ -71,15 +71,15 @@ describe Chef::Util::Backup do
end
it "should not delete anything if this is the only backup" do
- expect(@backup).to receive(:sorted_backup_files).and_return(['a'])
+ expect(@backup).to receive(:sorted_backup_files).and_return(["a"])
expect(@backup).not_to receive(:delete_backup)
@backup.backup!
end
it "should keep only 1 backup copy" do
- expect(@backup).to receive(:sorted_backup_files).and_return(['a', 'b', 'c'])
- expect(@backup).to receive(:delete_backup).with('b')
- expect(@backup).to receive(:delete_backup).with('c')
+ expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c"])
+ expect(@backup).to receive(:delete_backup).with("b")
+ expect(@backup).to receive(:delete_backup).with("c")
@backup.backup!
end
end
@@ -90,15 +90,15 @@ describe Chef::Util::Backup do
end
it "should not delete anything if we only have one other backup" do
- expect(@backup).to receive(:sorted_backup_files).and_return(['a', 'b'])
+ expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b"])
expect(@backup).not_to receive(:delete_backup)
@backup.backup!
end
it "should keep only 2 backup copies" do
- expect(@backup).to receive(:sorted_backup_files).and_return(['a', 'b', 'c', 'd'])
- expect(@backup).to receive(:delete_backup).with('c')
- expect(@backup).to receive(:delete_backup).with('d')
+ expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c", "d"])
+ expect(@backup).to receive(:delete_backup).with("c")
+ expect(@backup).to receive(:delete_backup).with("d")
@backup.backup!
end
end
@@ -106,7 +106,7 @@ describe Chef::Util::Backup do
describe "backup_filename" do
it "should return a timestamped path" do
- expect(@backup).to receive(:path).and_return('/a/b/c.txt')
+ expect(@backup).to receive(:path).and_return("/a/b/c.txt")
expect(@backup.send(:backup_filename)).to match(%r|^/a/b/c.txt.chef-\d{14}.\d{6}$|)
end
it "should strip the drive letter off for windows" do
@@ -114,21 +114,21 @@ describe Chef::Util::Backup do
expect(@backup.send(:backup_filename)).to match(%r|^\\a\\b\\c.txt.chef-\d{14}.\d{6}$|)
end
it "should strip the drive letter off for windows (with forwardslashes)" do
- expect(@backup).to receive(:path).and_return('c:/a/b/c.txt')
+ expect(@backup).to receive(:path).and_return("c:/a/b/c.txt")
expect(@backup.send(:backup_filename)).to match(%r|^/a/b/c.txt.chef-\d{14}.\d{6}$|)
end
end
describe "backup_path" do
it "uses the file's directory when Chef::Config[:file_backup_path] is nil" do
- expect(@backup).to receive(:path).and_return('/a/b/c.txt')
+ expect(@backup).to receive(:path).and_return("/a/b/c.txt")
Chef::Config[:file_backup_path] = nil
expect(@backup.send(:backup_path)).to match(%r|^/a/b/c.txt.chef-\d{14}.\d{6}$|)
end
it "uses the configured Chef::Config[:file_backup_path]" do
- expect(@backup).to receive(:path).and_return('/a/b/c.txt')
- Chef::Config[:file_backup_path] = '/backupdir'
+ expect(@backup).to receive(:path).and_return("/a/b/c.txt")
+ Chef::Config[:file_backup_path] = "/backupdir"
expect(@backup.send(:backup_path)).to match(%r|^/backupdir[\\/]+a/b/c.txt.chef-\d{14}.\d{6}$|)
end
diff --git a/spec/unit/util/diff_spec.rb b/spec/unit/util/diff_spec.rb
index b0a57a32c0..f46bc31488 100644
--- a/spec/unit/util/diff_spec.rb
+++ b/spec/unit/util/diff_spec.rb
@@ -17,8 +17,8 @@
#
-require 'spec_helper'
-require 'tmpdir'
+require "spec_helper"
+require "tmpdir"
shared_context "using file paths with spaces" do
let!(:old_tempfile) { Tempfile.new("chef-util diff-spec") }
diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb
index 9fbd3aaa51..f05780285f 100644
--- a/spec/unit/util/dsc/configuration_generator_spec.rb
+++ b/spec/unit/util/dsc/configuration_generator_spec.rb
@@ -16,25 +16,25 @@
# limitations under the License.
#
-require 'chef'
-require 'chef/util/dsc/configuration_generator'
+require "chef"
+require "chef/util/dsc/configuration_generator"
describe Chef::Util::DSC::ConfigurationGenerator do
let(:conf_man) do
node = Chef::Node.new
- Chef::Util::DSC::ConfigurationGenerator.new(node, 'tmp')
+ Chef::Util::DSC::ConfigurationGenerator.new(node, "tmp")
end
describe '#validate_configuration_name!' do
- it 'should not raise an error if a name contains all upper case letters' do
+ it "should not raise an error if a name contains all upper case letters" do
conf_man.send(:validate_configuration_name!, "HELLO")
end
- it 'should not raise an error if the name contains all lower case letters' do
+ it "should not raise an error if the name contains all lower case letters" do
conf_man.send(:validate_configuration_name!, "hello")
end
- it 'should not raise an error if no special characters are used except _' do
+ it "should not raise an error if no special characters are used except _" do
conf_man.send(:validate_configuration_name!, "hello_world")
end
@@ -48,67 +48,67 @@ describe Chef::Util::DSC::ConfigurationGenerator do
end
describe "#get_merged_configuration_flags" do
- context 'when strings are used as switches' do
- it 'should merge the hash if there are no restricted switches' do
- merged = conf_man.send(:get_merged_configuration_flags!, {'flag' => 'a'}, 'hello')
+ context "when strings are used as switches" do
+ it "should merge the hash if there are no restricted switches" do
+ merged = conf_man.send(:get_merged_configuration_flags!, {"flag" => "a"}, "hello")
expect(merged).to include(:flag)
- expect(merged[:flag]).to eql('a')
+ expect(merged[:flag]).to eql("a")
expect(merged).to include(:outputpath)
end
- it 'should raise an ArgumentError if you try to override outputpath' do
+ it "should raise an ArgumentError if you try to override outputpath" do
expect {
- conf_man.send(:get_merged_configuration_flags!, {'outputpath' => 'a'}, 'hello')
+ conf_man.send(:get_merged_configuration_flags!, {"outputpath" => "a"}, "hello")
}.to raise_error(ArgumentError)
end
- it 'should be case insensitive for switches that are not allowed' do
+ it "should be case insensitive for switches that are not allowed" do
expect {
- conf_man.send(:get_merged_configuration_flags!, {'OutputPath' => 'a'}, 'hello')
+ conf_man.send(:get_merged_configuration_flags!, {"OutputPath" => "a"}, "hello")
}.to raise_error(ArgumentError)
end
- it 'should be case insensitive to switches that are allowed' do
- merged = conf_man.send(:get_merged_configuration_flags!, {'FLAG' => 'a'}, 'hello')
+ it "should be case insensitive to switches that are allowed" do
+ merged = conf_man.send(:get_merged_configuration_flags!, {"FLAG" => "a"}, "hello")
expect(merged).to include(:flag)
end
end
- context 'when symbols are used as switches' do
- it 'should merge the hash if there are no restricted switches' do
- merged = conf_man.send(:get_merged_configuration_flags!, {:flag => 'a'}, 'hello')
+ context "when symbols are used as switches" do
+ it "should merge the hash if there are no restricted switches" do
+ merged = conf_man.send(:get_merged_configuration_flags!, {:flag => "a"}, "hello")
expect(merged).to include(:flag)
- expect(merged[:flag]).to eql('a')
+ expect(merged[:flag]).to eql("a")
expect(merged).to include(:outputpath)
end
- it 'should raise an ArgumentError if you try to override outputpath' do
+ it "should raise an ArgumentError if you try to override outputpath" do
expect {
- conf_man.send(:get_merged_configuration_flags!, {:outputpath => 'a'}, 'hello')
+ conf_man.send(:get_merged_configuration_flags!, {:outputpath => "a"}, "hello")
}.to raise_error(ArgumentError)
end
- it 'should be case insensitive for switches that are not allowed' do
+ it "should be case insensitive for switches that are not allowed" do
expect {
- conf_man.send(:get_merged_configuration_flags!, {:OutputPath => 'a'}, 'hello')
+ conf_man.send(:get_merged_configuration_flags!, {:OutputPath => "a"}, "hello")
}.to raise_error(ArgumentError)
end
- it 'should be case insensitive to switches that are allowed' do
- merged = conf_man.send(:get_merged_configuration_flags!, {:FLAG => 'a'}, 'hello')
+ it "should be case insensitive to switches that are allowed" do
+ merged = conf_man.send(:get_merged_configuration_flags!, {:FLAG => "a"}, "hello")
expect(merged).to include(:flag)
end
end
- context 'when there are no flags' do
- it 'should supply an output path if configuration_flags is an empty hash' do
- merged = conf_man.send(:get_merged_configuration_flags!, {}, 'hello')
+ context "when there are no flags" do
+ it "should supply an output path if configuration_flags is an empty hash" do
+ merged = conf_man.send(:get_merged_configuration_flags!, {}, "hello")
expect(merged).to include(:outputpath)
expect(merged.length).to eql(1)
end
- it 'should supply an output path if configuration_flags is an empty hash' do
- merged = conf_man.send(:get_merged_configuration_flags!, nil, 'hello')
+ it "should supply an output path if configuration_flags is an empty hash" do
+ merged = conf_man.send(:get_merged_configuration_flags!, nil, "hello")
expect(merged).to include(:outputpath)
expect(merged.length).to eql(1)
end
@@ -130,7 +130,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do
[a,b].join("++")
end
allow(file_like_object).to receive(:write)
- conf_man.send(:write_document_generation_script, 'file', 'hello', {})
+ conf_man.send(:write_document_generation_script, "file", "hello", {})
expect(file_like_object).to have_received(:write)
end
end
@@ -143,24 +143,24 @@ describe Chef::Util::DSC::ConfigurationGenerator do
[a,b].join("++")
end
- allow(Dir).to receive(:entries).with("tmp++hello") {['f1', 'f2', 'hello.mof', 'f3']}
- expect(conf_man.send(:find_configuration_document, 'hello')).to eql('tmp++hello++hello.mof')
+ allow(Dir).to receive(:entries).with("tmp++hello") {["f1", "f2", "hello.mof", "f3"]}
+ expect(conf_man.send(:find_configuration_document, "hello")).to eql("tmp++hello++hello.mof")
end
it "should return nil if the mof file is not found" do
allow(File).to receive(:join) do |a, b|
[a,b].join("++")
end
- allow(Dir).to receive(:entries).with("tmp++hello") {['f1', 'f2', 'f3']}
- expect(conf_man.send(:find_configuration_document, 'hello')).to be_nil
+ allow(Dir).to receive(:entries).with("tmp++hello") {["f1", "f2", "f3"]}
+ expect(conf_man.send(:find_configuration_document, "hello")).to be_nil
end
end
describe "#configuration_code" do
it "should build dsc" do
- dsc = conf_man.send(:configuration_code, 'archive{}', 'hello', {})
+ dsc = conf_man.send(:configuration_code, "archive{}", "hello", {})
found_configuration = false
- dsc.split(';').each do |command|
+ dsc.split(";").each do |command|
if command.downcase =~ /\s*configuration\s+'hello'\s*\{\s*node\s+'localhost'\s*\{\s*archive\s*\{\s*\}\s*\}\s*\}\s*/
found_configuration = true
end
@@ -169,22 +169,22 @@ describe Chef::Util::DSC::ConfigurationGenerator do
end
context "with imports" do
it "should import all resources when a module has an empty list" do
- dsc = conf_man.send(:configuration_code, 'archive{}', 'hello', {'FooModule' => []})
+ dsc = conf_man.send(:configuration_code, "archive{}", "hello", {"FooModule" => []})
expect(dsc).to match(/Import-DscResource -ModuleName FooModule\s*\n/)
end
it "should import all resources when a module has a list with *" do
- dsc = conf_man.send(:configuration_code, 'archive{}', 'hello', {'FooModule' => ['FooResource', '*', 'BarResource']})
+ dsc = conf_man.send(:configuration_code, "archive{}", "hello", {"FooModule" => ["FooResource", "*", "BarResource"]})
expect(dsc).to match(/Import-DscResource -ModuleName FooModule\s*\n/)
end
it "should import specific resources when a module has list without * that is not empty" do
- dsc = conf_man.send(:configuration_code, 'archive{}', 'hello', {'FooModule' => ['FooResource', 'BarResource']})
+ dsc = conf_man.send(:configuration_code, "archive{}", "hello", {"FooModule" => ["FooResource", "BarResource"]})
expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/)
end
it "should import multiple modules with multiple import statements" do
- dsc = conf_man.send(:configuration_code, 'archive{}', 'hello', {'FooModule' => ['FooResource', 'BarResource'], 'BazModule' => []})
+ dsc = conf_man.send(:configuration_code, "archive{}", "hello", {"FooModule" => ["FooResource", "BarResource"], "BazModule" => []})
expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/)
expect(dsc).to match(/Import-DscResource -ModuleName BazModule\s*\n/)
end
diff --git a/spec/unit/util/dsc/lcm_output_parser_spec.rb b/spec/unit/util/dsc/lcm_output_parser_spec.rb
index 3d44e07885..2990e1f28e 100644
--- a/spec/unit/util/dsc/lcm_output_parser_spec.rb
+++ b/spec/unit/util/dsc/lcm_output_parser_spec.rb
@@ -16,24 +16,24 @@
# limitations under the License.
#
-require 'chef/util/dsc/lcm_output_parser'
+require "chef/util/dsc/lcm_output_parser"
describe Chef::Util::DSC::LocalConfigurationManager::Parser do
- context 'empty input parameter' do
- it 'raises an exception when there are no valid lines' do
+ context "empty input parameter" do
+ it "raises an exception when there are no valid lines" do
str = <<-EOF
EOF
expect {Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)}.to raise_error(Chef::Exceptions::LCMParser)
end
- it 'raises an exception for a nil input' do
+ it "raises an exception for a nil input" do
expect {Chef::Util::DSC::LocalConfigurationManager::Parser::parse(nil)}.to raise_error(Chef::Exceptions::LCMParser)
end
end
- context 'correctly formatted output from lcm' do
- it 'returns a single resource when only 1 logged with the correct name' do
+ context "correctly formatted output from lcm" do
+ it "returns a single resource when only 1 logged with the correct name" do
str = <<EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -42,10 +42,10 @@ logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
expect(resources.length).to eq(1)
- expect(resources[0].name).to eq('[name]')
+ expect(resources[0].name).to eq("[name]")
end
- it 'identifies when a resource changes the state of the system' do
+ it "identifies when a resource changes the state of the system" do
str = <<EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -58,7 +58,7 @@ EOF
expect(resources[0].changes_state?).to be_truthy
end
- it 'preserves the log provided for how the system changed the state' do
+ it "preserves the log provided for how the system changed the state" do
str = <<EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -72,7 +72,7 @@ EOF
expect(resources[0].change_log).to match_array(["[name]","[message]","[name]"])
end
- it 'should return false for changes_state?' do
+ it "should return false for changes_state?" do
str = <<EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -84,7 +84,7 @@ EOF
expect(resources[0].changes_state?).to be_falsey
end
- it 'should return an empty array for change_log if changes_state? is false' do
+ it "should return an empty array for change_log if changes_state? is false" do
str = <<EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -97,8 +97,8 @@ EOF
end
end
- context 'Incorrectly formatted output from LCM' do
- it 'should allow missing a [End Resource] when its the last one and still find all the resource' do
+ context "Incorrectly formatted output from LCM" do
+ it "should allow missing a [End Resource] when its the last one and still find all the resource" do
str = <<-EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -119,7 +119,7 @@ EOF
expect(resources[1].changes_state?).to be_truthy
end
- it 'should allow missing a [End Resource] when its the first one and still find all the resource' do
+ it "should allow missing a [End Resource] when its the first one and still find all the resource" do
str = <<-EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -140,7 +140,7 @@ EOF
expect(resources[1].changes_state?).to be_truthy
end
- it 'should allow missing set and end resource and assume an unconverged resource in this case' do
+ it "should allow missing set and end resource and assume an unconverged resource in this case" do
str = <<-EOF
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ Start Resource ] [name]
@@ -156,9 +156,9 @@ logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
expect(resources[0].changes_state?).to be_truthy
- expect(resources[0].name).to eql('[name]')
+ expect(resources[0].name).to eql("[name]")
expect(resources[1].changes_state?).to be_truthy
- expect(resources[1].name).to eql('[name2]')
+ expect(resources[1].name).to eql("[name2]")
end
end
end
diff --git a/spec/unit/util/dsc/local_configuration_manager_spec.rb b/spec/unit/util/dsc/local_configuration_manager_spec.rb
index 1cff9e445b..eb860b5c30 100644
--- a/spec/unit/util/dsc/local_configuration_manager_spec.rb
+++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb
@@ -16,12 +16,12 @@
# limitations under the License.
#
-require 'chef'
-require 'chef/util/dsc/local_configuration_manager'
+require "chef"
+require "chef/util/dsc/local_configuration_manager"
describe Chef::Util::DSC::LocalConfigurationManager do
- let(:lcm) { Chef::Util::DSC::LocalConfigurationManager.new(nil, 'tmp') }
+ let(:lcm) { Chef::Util::DSC::LocalConfigurationManager.new(nil, "tmp") }
let(:normal_lcm_output) { <<-EOH
logtype: [machinename]: LCM: [ Start Set ]
@@ -50,12 +50,12 @@ EOH
double("LCM cmdlet status", :stderr => lcm_standard_error, :return_value => lcm_standard_output, :succeeded? => lcm_cmdlet_success)
}
- describe 'test_configuration method invocation' do
- context 'when interacting with the LCM using a PowerShell cmdlet' do
+ describe "test_configuration method invocation" do
+ context "when interacting with the LCM using a PowerShell cmdlet" do
before(:each) do
allow(lcm).to receive(:run_configuration_cmdlet).and_return(lcm_status)
end
- context 'that returns successfully' do
+ context "that returns successfully" do
before(:each) do
allow(lcm).to receive(:run_configuration_cmdlet).and_return(lcm_status)
end
@@ -64,16 +64,16 @@ EOH
let(:lcm_standard_error) { nil }
let(:lcm_cmdlet_success) { true }
- it 'should successfully return resource information for normally formatted output when cmdlet the cmdlet succeeds' do
- test_configuration_result = lcm.test_configuration('config', {})
+ it "should successfully return resource information for normally formatted output when cmdlet the cmdlet succeeds" do
+ test_configuration_result = lcm.test_configuration("config", {})
expect(test_configuration_result.class).to be(Array)
expect(test_configuration_result.length).to be > 0
expect(Chef::Log).not_to receive(:warn)
end
end
- context 'that fails due to missing what-if switch in DSC resource cmdlet implementation' do
- let(:lcm_standard_output) { '' }
+ context "that fails due to missing what-if switch in DSC resource cmdlet implementation" do
+ let(:lcm_standard_output) { "" }
let(:lcm_standard_error) { no_whatif_lcm_output }
let(:lcm_cmdlet_success) { false }
@@ -81,58 +81,58 @@ EOH
expect(lcm.send(:whatif_not_supported?, no_whatif_lcm_output)).to be_truthy
end
- it 'should should return a (possibly empty) array of ResourceInfo instances' do
+ it "should should return a (possibly empty) array of ResourceInfo instances" do
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:whatif_not_supported?).and_call_original
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration("config", {})}.not_to raise_error
expect(test_configuration_result.class).to be(Array)
end
end
- context 'that fails due to a DSC resource not being imported before StartDSCConfiguration -whatif is executed' do
- let(:lcm_standard_output) { '' }
+ context "that fails due to a DSC resource not being imported before StartDSCConfiguration -whatif is executed" do
+ let(:lcm_standard_output) { "" }
let(:lcm_standard_error) { dsc_resource_import_failure_output }
let(:lcm_cmdlet_success) { false }
- it 'should log a warning if the message is formatted as expected when a resource import failure occurs' do
+ it "should log a warning if the message is formatted as expected when a resource import failure occurs" do
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:dsc_module_import_failure?).and_call_original
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration("config", {})}.not_to raise_error
end
- it 'should return a (possibly empty) array of ResourceInfo instances' do
+ it "should return a (possibly empty) array of ResourceInfo instances" do
expect(Chef::Log).to receive(:warn).at_least(:once)
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration("config", {})}.not_to raise_error
expect(test_configuration_result.class).to be(Array)
end
end
- context 'that fails due to an unknown PowerShell cmdlet error' do
- let(:lcm_standard_output) { 'some output' }
- let(:lcm_standard_error) { 'Abort, Retry, Fail?' }
+ context "that fails due to an unknown PowerShell cmdlet error" do
+ let(:lcm_standard_output) { "some output" }
+ let(:lcm_standard_error) { "Abort, Retry, Fail?" }
let(:lcm_cmdlet_success) { false }
- it 'should log a warning' do
+ it "should log a warning" do
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:dsc_module_import_failure?).and_call_original
- expect {lcm.test_configuration('config', {})}.not_to raise_error
+ expect {lcm.test_configuration("config", {})}.not_to raise_error
end
end
end
- it 'should identify a correctly formatted error message as a resource import failure' do
+ it "should identify a correctly formatted error message as a resource import failure" do
expect(lcm.send(:dsc_module_import_failure?, dsc_resource_import_failure_output)).to be(true)
end
- it 'should not identify an incorrectly formatted error message as a resource import failure' do
- expect(lcm.send(:dsc_module_import_failure?, dsc_resource_import_failure_output.gsub('module', 'gibberish'))).to be(false)
+ it "should not identify an incorrectly formatted error message as a resource import failure" do
+ expect(lcm.send(:dsc_module_import_failure?, dsc_resource_import_failure_output.gsub("module", "gibberish"))).to be(false)
end
- it 'should not identify a message without a CimException reference as a resource import failure' do
- expect(lcm.send(:dsc_module_import_failure?, dsc_resource_import_failure_output.gsub('CimException', 'ArgumentException'))).to be(false)
+ it "should not identify a message without a CimException reference as a resource import failure" do
+ expect(lcm.send(:dsc_module_import_failure?, dsc_resource_import_failure_output.gsub("CimException", "ArgumentException"))).to be(false)
end
end
end
diff --git a/spec/unit/util/dsc/resource_store.rb b/spec/unit/util/dsc/resource_store.rb
index 181ac2bb6c..97652a3d1c 100644
--- a/spec/unit/util/dsc/resource_store.rb
+++ b/spec/unit/util/dsc/resource_store.rb
@@ -16,61 +16,61 @@
# limitations under the License.
#
-require 'chef'
-require 'chef/util/dsc/resource_store'
+require "chef"
+require "chef/util/dsc/resource_store"
describe Chef::Util::DSC::ResourceStore do
let(:resource_store) { Chef::Util::DSC::ResourceStore.new }
let(:resource_a) { {
- 'ResourceType' => 'AFoo',
- 'Name' => 'Foo',
- 'Module' => {'Name' => 'ModuleA'},
+ "ResourceType" => "AFoo",
+ "Name" => "Foo",
+ "Module" => {"Name" => "ModuleA"},
}
}
let(:resource_b) { {
- 'ResourceType' => 'BFoo',
- 'Name' => 'Foo',
- 'Module' => {'Name' => 'ModuleB'},
+ "ResourceType" => "BFoo",
+ "Name" => "Foo",
+ "Module" => {"Name" => "ModuleB"},
}
}
- context 'when resources are not cached' do
+ context "when resources are not cached" do
context 'when calling #resources' do
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(resource_store.resources).to eql([])
end
end
context 'when calling #find' do
- it 'returns an empty list if it cannot find any matching resources' do
+ it "returns an empty list if it cannot find any matching resources" do
expect(resource_store).to receive(:query_resource).and_return([])
- expect(resource_store.find('foo')).to eql([])
+ expect(resource_store.find("foo")).to eql([])
end
- it 'returns the resource if it is found (comparisons are case insensitive)' do
+ it "returns the resource if it is found (comparisons are case insensitive)" do
expect(resource_store).to receive(:query_resource).and_return([resource_a])
- expect(resource_store.find('foo')).to eql([resource_a])
+ expect(resource_store.find("foo")).to eql([resource_a])
end
- it 'returns multiple resoures if they are found' do
+ it "returns multiple resoures if they are found" do
expect(resource_store).to receive(:query_resource).and_return([resource_a, resource_b])
- expect(resource_store.find('foo')).to include(resource_a, resource_b)
+ expect(resource_store.find("foo")).to include(resource_a, resource_b)
end
- it 'deduplicates resources by ResourceName' do
+ it "deduplicates resources by ResourceName" do
expect(resource_store).to receive(:query_resource).and_return([resource_a, resource_a])
- resource_store.find('foo')
+ resource_store.find("foo")
expect(resource_store.resources).to eq([resource_a])
end
end
end
- context 'when resources are cached' do
- it 'recalls resources from the cache if present' do
+ context "when resources are cached" do
+ it "recalls resources from the cache if present" do
expect(resource_store).not_to receive(:query_resource)
expect(resource_store).to receive(:resources).and_return([resource_a])
- resource_store.find('foo')
+ resource_store.find("foo")
end
end
end
diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb
index 968302df17..9db7e85931 100644
--- a/spec/unit/util/editor_spec.rb
+++ b/spec/unit/util/editor_spec.rb
@@ -1,14 +1,14 @@
-require 'spec_helper'
-require 'chef/util/editor'
+require "spec_helper"
+require "chef/util/editor"
describe Chef::Util::Editor do
describe '#initialize' do
- it 'takes an Enumerable of lines' do
+ it "takes an Enumerable of lines" do
editor = described_class.new(File.open(__FILE__))
expect(editor.lines).to be == IO.readlines(__FILE__)
end
- it 'makes a copy of an Array' do
+ it "makes a copy of an Array" do
array = Array.new
editor = described_class.new(array)
expect(editor.lines).to_not be(array)
@@ -16,137 +16,137 @@ describe Chef::Util::Editor do
end
subject(:editor) { described_class.new(input_lines) }
- let(:input_lines) { ['one', 'two', 'two', 'three'] }
+ let(:input_lines) { ["one", "two", "two", "three"] }
describe '#append_line_after' do
- context 'when there is no match' do
- subject(:execute) { editor.append_line_after('missing', 'new') }
+ context "when there is no match" do
+ subject(:execute) { editor.append_line_after("missing", "new") }
- it('returns the number of added lines') { is_expected.to eq(0) }
- it 'does not add any lines' do
+ it("returns the number of added lines") { is_expected.to eq(0) }
+ it "does not add any lines" do
expect { execute }.to_not change { editor.lines }
end
end
- context 'when there is a match' do
- subject(:execute) { editor.append_line_after('two', 'new') }
+ context "when there is a match" do
+ subject(:execute) { editor.append_line_after("two", "new") }
- it('returns the number of added lines') { is_expected.to eq(2) }
- it 'adds a line after each match' do
+ it("returns the number of added lines") { is_expected.to eq(2) }
+ it "adds a line after each match" do
execute
- expect(editor.lines).to be == ['one', 'two', 'new', 'two', 'new', 'three']
+ expect(editor.lines).to be == ["one", "two", "new", "two", "new", "three"]
end
end
- it 'matches a Regexp' do
- expect(editor.append_line_after(/^ee/, 'new')).to be == 0
- expect(editor.append_line_after(/ee$/, 'new')).to be == 1
+ it "matches a Regexp" do
+ expect(editor.append_line_after(/^ee/, "new")).to be == 0
+ expect(editor.append_line_after(/ee$/, "new")).to be == 1
end
end
describe '#append_line_if_missing' do
- context 'when there is no match' do
- subject(:execute) { editor.append_line_if_missing('missing', 'new') }
+ context "when there is no match" do
+ subject(:execute) { editor.append_line_if_missing("missing", "new") }
- it('returns the number of added lines') { is_expected.to eq(1) }
- it 'adds a line to the end' do
+ it("returns the number of added lines") { is_expected.to eq(1) }
+ it "adds a line to the end" do
execute
- expect(editor.lines).to be == ['one', 'two', 'two', 'three', 'new']
+ expect(editor.lines).to be == ["one", "two", "two", "three", "new"]
end
end
- context 'when there is a match' do
- subject(:execute) { editor.append_line_if_missing('one', 'new') }
+ context "when there is a match" do
+ subject(:execute) { editor.append_line_if_missing("one", "new") }
- it('returns the number of added lines') { is_expected.to eq(0) }
- it 'does not add any lines' do
+ it("returns the number of added lines") { is_expected.to eq(0) }
+ it "does not add any lines" do
expect { execute }.to_not change { editor.lines }
end
end
- it 'matches a Regexp' do
- expect(editor.append_line_if_missing(/ee$/, 'new')).to be == 0
- expect(editor.append_line_if_missing(/^ee/, 'new')).to be == 1
+ it "matches a Regexp" do
+ expect(editor.append_line_if_missing(/ee$/, "new")).to be == 0
+ expect(editor.append_line_if_missing(/^ee/, "new")).to be == 1
end
end
describe '#remove_lines' do
- context 'when there is no match' do
- subject(:execute) { editor.remove_lines('missing') }
+ context "when there is no match" do
+ subject(:execute) { editor.remove_lines("missing") }
- it('returns the number of removed lines') { is_expected.to eq(0) }
- it 'does not remove any lines' do
+ it("returns the number of removed lines") { is_expected.to eq(0) }
+ it "does not remove any lines" do
expect { execute }.to_not change { editor.lines }
end
end
- context 'when there is a match' do
- subject(:execute) { editor.remove_lines('two') }
+ context "when there is a match" do
+ subject(:execute) { editor.remove_lines("two") }
- it('returns the number of removed lines') { is_expected.to eq(2) }
- it 'removes the matching lines' do
+ it("returns the number of removed lines") { is_expected.to eq(2) }
+ it "removes the matching lines" do
execute
- expect(editor.lines).to be == ['one', 'three']
+ expect(editor.lines).to be == ["one", "three"]
end
end
- it 'matches a Regexp' do
+ it "matches a Regexp" do
expect(editor.remove_lines(/^ee/)).to be == 0
expect(editor.remove_lines(/ee$/)).to be == 1
end
end
describe '#replace' do
- context 'when there is no match' do
- subject(:execute) { editor.replace('missing', 'new') }
+ context "when there is no match" do
+ subject(:execute) { editor.replace("missing", "new") }
- it('returns the number of changed lines') { is_expected.to eq(0) }
- it 'does not change any lines' do
+ it("returns the number of changed lines") { is_expected.to eq(0) }
+ it "does not change any lines" do
expect { execute }.to_not change { editor.lines }
end
end
- context 'when there is a match' do
- subject(:execute) { editor.replace('two', 'new') }
+ context "when there is a match" do
+ subject(:execute) { editor.replace("two", "new") }
- it('returns the number of changed lines') { is_expected.to eq(2) }
- it 'replaces the matching portions' do
+ it("returns the number of changed lines") { is_expected.to eq(2) }
+ it "replaces the matching portions" do
execute
- expect(editor.lines).to be == ['one', 'new', 'new', 'three']
+ expect(editor.lines).to be == ["one", "new", "new", "three"]
end
end
- it 'matches a Regexp' do
- expect(editor.replace(/^ee/, 'new')).to be == 0
- expect(editor.replace(/ee$/, 'new')).to be == 1
- expect(editor.lines).to be == ['one', 'two', 'two', 'thrnew']
+ it "matches a Regexp" do
+ expect(editor.replace(/^ee/, "new")).to be == 0
+ expect(editor.replace(/ee$/, "new")).to be == 1
+ expect(editor.lines).to be == ["one", "two", "two", "thrnew"]
end
end
describe '#replace_lines' do
- context 'when there is no match' do
- subject(:execute) { editor.replace_lines('missing', 'new') }
+ context "when there is no match" do
+ subject(:execute) { editor.replace_lines("missing", "new") }
- it('returns the number of changed lines') { is_expected.to eq(0) }
- it 'does not change any lines' do
+ it("returns the number of changed lines") { is_expected.to eq(0) }
+ it "does not change any lines" do
expect { execute }.to_not change { editor.lines }
end
end
- context 'when there is a match' do
- subject(:execute) { editor.replace_lines('two', 'new') }
+ context "when there is a match" do
+ subject(:execute) { editor.replace_lines("two", "new") }
- it('returns the number of replaced lines') { is_expected.to eq(2) }
- it 'replaces the matching line' do
+ it("returns the number of replaced lines") { is_expected.to eq(2) }
+ it "replaces the matching line" do
execute
- expect(editor.lines).to be == ['one', 'new', 'new', 'three']
+ expect(editor.lines).to be == ["one", "new", "new", "three"]
end
end
- it 'matches a Regexp' do
- expect(editor.replace_lines(/^ee/, 'new')).to be == 0
- expect(editor.replace_lines(/ee$/, 'new')).to be == 1
- expect(editor.lines).to be == ['one', 'two', 'two', 'new']
+ it "matches a Regexp" do
+ expect(editor.replace_lines(/^ee/, "new")).to be == 0
+ expect(editor.replace_lines(/ee$/, "new")).to be == 1
+ expect(editor.lines).to be == ["one", "two", "two", "new"]
end
end
end
diff --git a/spec/unit/util/file_edit_spec.rb b/spec/unit/util/file_edit_spec.rb
index b99cf2f426..5f9b559a4c 100644
--- a/spec/unit/util/file_edit_spec.rb
+++ b/spec/unit/util/file_edit_spec.rb
@@ -16,8 +16,8 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'tempfile'
+require "spec_helper"
+require "tempfile"
describe Chef::Util::FileEdit do
@@ -93,7 +93,7 @@ twice
end
let(:target_file) do
- f = Tempfile.open('file_edit_spec')
+ f = Tempfile.open("file_edit_spec")
f.write(starting_content)
f.close
f
diff --git a/spec/unit/util/powershell/cmdlet_spec.rb b/spec/unit/util/powershell/cmdlet_spec.rb
index 5ddf9282c4..d2a7960db2 100644
--- a/spec/unit/util/powershell/cmdlet_spec.rb
+++ b/spec/unit/util/powershell/cmdlet_spec.rb
@@ -16,25 +16,25 @@
# limitations under the License.
#
-require 'chef'
-require 'chef/util/powershell/cmdlet'
+require "chef"
+require "chef/util/powershell/cmdlet"
describe Chef::Util::Powershell::Cmdlet do
before (:all) do
@node = Chef::Node.new
- @cmdlet = Chef::Util::Powershell::Cmdlet.new(@node, 'Some-Commandlet')
+ @cmdlet = Chef::Util::Powershell::Cmdlet.new(@node, "Some-Commandlet")
end
describe '#validate_switch_name!' do
- it 'should not raise an error if a name contains all upper case letters' do
+ it "should not raise an error if a name contains all upper case letters" do
@cmdlet.send(:validate_switch_name!, "HELLO")
end
- it 'should not raise an error if the name contains all lower case letters' do
+ it "should not raise an error if the name contains all lower case letters" do
@cmdlet.send(:validate_switch_name!, "hello")
end
- it 'should not raise an error if no special characters are used except _' do
+ it "should not raise an error if no special characters are used except _" do
@cmdlet.send(:validate_switch_name!, "hello_world")
end
@@ -55,51 +55,51 @@ describe Chef::Util::Powershell::Cmdlet do
end
end
- it 'does not do anything to a string without special characters' do
- expect(@cmdlet.send(:escape_parameter_value, 'stuff')).to eql('stuff')
+ it "does not do anything to a string without special characters" do
+ expect(@cmdlet.send(:escape_parameter_value, "stuff")).to eql("stuff")
end
end
describe '#escape_string_parameter_value' do
it "surrounds a string with ''" do
- expect(@cmdlet.send(:escape_string_parameter_value, 'stuff')).to eql("'stuff'")
+ expect(@cmdlet.send(:escape_string_parameter_value, "stuff")).to eql("'stuff'")
end
end
describe '#command_switches_string' do
- it 'raises an ArgumentError if the key is not a symbol' do
+ it "raises an ArgumentError if the key is not a symbol" do
expect {
- @cmdlet.send(:command_switches_string, {'foo' => 'bar'})
+ @cmdlet.send(:command_switches_string, {"foo" => "bar"})
}.to raise_error(ArgumentError)
end
- it 'does not allow invalid switch names' do
+ it "does not allow invalid switch names" do
expect {
- @cmdlet.send(:command_switches_string, {:foo! => 'bar'})
+ @cmdlet.send(:command_switches_string, {:foo! => "bar"})
}.to raise_error(ArgumentError)
end
- it 'ignores switches with a false value' do
- expect(@cmdlet.send(:command_switches_string, {foo: false})).to eql('')
+ it "ignores switches with a false value" do
+ expect(@cmdlet.send(:command_switches_string, {foo: false})).to eql("")
end
- it 'should correctly handle a value type of string' do
- expect(@cmdlet.send(:command_switches_string, {foo: 'bar'})).to eql("-foo 'bar'")
+ it "should correctly handle a value type of string" do
+ expect(@cmdlet.send(:command_switches_string, {foo: "bar"})).to eql("-foo 'bar'")
end
- it 'should correctly handle a value type of string even when it is 0 length' do
- expect(@cmdlet.send(:command_switches_string, {foo: ''})).to eql("-foo ''")
+ it "should correctly handle a value type of string even when it is 0 length" do
+ expect(@cmdlet.send(:command_switches_string, {foo: ""})).to eql("-foo ''")
end
- it 'should not quote integers' do
+ it "should not quote integers" do
expect(@cmdlet.send(:command_switches_string, {foo: 1})).to eql("-foo 1")
end
- it 'should not quote floats' do
+ it "should not quote floats" do
expect(@cmdlet.send(:command_switches_string, {foo: 1.0})).to eql("-foo 1.0")
end
- it 'has just the switch when the value is true' do
+ it "has just the switch when the value is true" do
expect(@cmdlet.send(:command_switches_string, {foo: true})).to eql("-foo")
end
end
diff --git a/spec/unit/util/powershell/ps_credential_spec.rb b/spec/unit/util/powershell/ps_credential_spec.rb
index 668ec525c6..2ec7ff6238 100644
--- a/spec/unit/util/powershell/ps_credential_spec.rb
+++ b/spec/unit/util/powershell/ps_credential_spec.rb
@@ -16,27 +16,27 @@
# limitations under the License.
#
-require 'chef'
-require 'chef/util/powershell/ps_credential'
+require "chef"
+require "chef/util/powershell/ps_credential"
describe Chef::Util::Powershell::PSCredential do
- let (:username) { 'foo' }
- let (:password) { 'ThIsIsThEpAsSwOrD' }
+ let (:username) { "foo" }
+ let (:password) { "ThIsIsThEpAsSwOrD" }
- context 'when username and password are provided' do
+ context "when username and password are provided" do
let(:ps_credential) { Chef::Util::Powershell::PSCredential.new(username, password)}
- context 'when calling to_psobject' do
- it 'should create the script to create a PSCredential when calling' do
- allow(ps_credential).to receive(:encrypt).with(password).and_return('encrypted')
+ context "when calling to_psobject" do
+ it "should create the script to create a PSCredential when calling" do
+ allow(ps_credential).to receive(:encrypt).with(password).and_return("encrypted")
expect(ps_credential.to_psobject).to eq(
"New-Object System.Management.Automation.PSCredential("\
"'#{username}',('encrypted' | ConvertTo-SecureString))")
end
end
- context 'when to_text is called' do
- it 'should not contain the password' do
- allow(ps_credential).to receive(:encrypt).with(password).and_return('encrypted')
+ context "when to_text is called" do
+ it "should not contain the password" do
+ allow(ps_credential).to receive(:encrypt).with(password).and_return("encrypted")
expect(ps_credential.to_text).not_to match(/#{password}/)
end
end
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index 0ed138c7bc..60f1ba8fae 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -17,7 +17,7 @@
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Util::Selinux do
class TestClass
@@ -40,7 +40,7 @@ describe Chef::Util::Selinux do
end
it "each part of ENV['PATH'] should be checked" do
- expected_paths = ENV['PATH'].split(File::PATH_SEPARATOR) + [ '/bin', '/usr/bin', '/sbin', '/usr/sbin' ]
+ expected_paths = ENV["PATH"].split(File::PATH_SEPARATOR) + [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
expected_paths.each do |bin_path|
selinux_path = File.join(bin_path, "selinuxenabled")
diff --git a/spec/unit/util/threaded_job_queue_spec.rb b/spec/unit/util/threaded_job_queue_spec.rb
index 22626328be..e4eb58d8bd 100644
--- a/spec/unit/util/threaded_job_queue_spec.rb
+++ b/spec/unit/util/threaded_job_queue_spec.rb
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-require 'spec_helper'
+require "spec_helper"
class WorkerThreadError < StandardError
end