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.rb64
-rw-r--r--spec/unit/util/diff_spec.rb50
-rw-r--r--spec/unit/util/dsc/configuration_generator_spec.rb26
-rw-r--r--spec/unit/util/dsc/lcm_output_parser_spec.rb34
-rw-r--r--spec/unit/util/dsc/local_configuration_manager_spec.rb2
-rw-r--r--spec/unit/util/editor_spec.rb20
-rw-r--r--spec/unit/util/file_edit_spec.rb20
-rw-r--r--spec/unit/util/path_helper_spec.rb72
-rw-r--r--spec/unit/util/powershell/cmdlet_spec.rb18
-rw-r--r--spec/unit/util/selinux_spec.rb60
-rw-r--r--spec/unit/util/threaded_job_queue_spec.rb12
11 files changed, 189 insertions, 189 deletions
diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb
index 617886cede..f548e8241d 100644
--- a/spec/unit/util/backup_spec.rb
+++ b/spec/unit/util/backup_spec.rb
@@ -28,33 +28,33 @@ describe Chef::Util::Backup do
before(:each) do
@new_resource = double("new_resource")
- @new_resource.should_receive(:path).at_least(:once).and_return(tempfile.path)
+ expect(@new_resource).to receive(:path).at_least(:once).and_return(tempfile.path)
@backup = Chef::Util::Backup.new(@new_resource)
end
it "should store the resource passed to new as new_resource" do
- @backup.new_resource.should eql(@new_resource)
+ expect(@backup.new_resource).to eql(@new_resource)
end
describe "for cases when we don't want to back anything up" do
before(:each) do
- @backup.should_not_receive(:do_backup)
+ expect(@backup).not_to receive(:do_backup)
end
it "should not attempt to backup a file if :backup is false" do
- @new_resource.should_receive(:backup).at_least(:once).and_return(false)
+ expect(@new_resource).to receive(:backup).at_least(:once).and_return(false)
@backup.backup!
end
it "should not attempt to backup a file if :backup == 0" do
- @new_resource.should_receive(:backup).at_least(:once).and_return(0)
+ expect(@new_resource).to receive(:backup).at_least(:once).and_return(0)
@backup.backup!
end
it "should not attempt to backup a file if it does not exist" do
- @new_resource.should_receive(:backup).at_least(:once).and_return(1)
- File.should_receive(:exist?).with(tempfile.path).at_least(:once).and_return(false)
+ expect(@new_resource).to receive(:backup).at_least(:once).and_return(1)
+ expect(File).to receive(:exist?).with(tempfile.path).at_least(:once).and_return(false)
@backup.backup!
end
@@ -62,43 +62,43 @@ describe Chef::Util::Backup do
describe "for cases when we want to back things up" do
before(:each) do
- @backup.should_receive(:do_backup)
+ expect(@backup).to receive(:do_backup)
end
describe "when the number of backups is specified as 1" do
before(:each) do
- @new_resource.should_receive(:backup).at_least(:once).and_return(1)
+ expect(@new_resource).to receive(:backup).at_least(:once).and_return(1)
end
it "should not delete anything if this is the only backup" do
- @backup.should_receive(:sorted_backup_files).and_return(['a'])
- @backup.should_not_receive(:delete_backup)
+ 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
- @backup.should_receive(:sorted_backup_files).and_return(['a', 'b', 'c'])
- @backup.should_receive(:delete_backup).with('b')
- @backup.should_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
describe "when the number of backups is specified as 2" do
before(:each) do
- @new_resource.should_receive(:backup).at_least(:once).and_return(2)
+ expect(@new_resource).to receive(:backup).at_least(:once).and_return(2)
end
it "should not delete anything if we only have one other backup" do
- @backup.should_receive(:sorted_backup_files).and_return(['a', 'b'])
- @backup.should_not_receive(:delete_backup)
+ 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
- @backup.should_receive(:sorted_backup_files).and_return(['a', 'b', 'c', 'd'])
- @backup.should_receive(:delete_backup).with('c')
- @backup.should_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,36 +106,36 @@ describe Chef::Util::Backup do
describe "backup_filename" do
it "should return a timestamped path" do
- @backup.should_receive(:path).and_return('/a/b/c.txt')
- @backup.send(:backup_filename).should =~ %r|^/a/b/c.txt.chef-\d{14}.\d{6}$|
+ 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
- @backup.should_receive(:path).and_return('c:\a\b\c.txt')
- @backup.send(:backup_filename).should =~ %r|^\\a\\b\\c.txt.chef-\d{14}.\d{6}$|
+ 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
it "should strip the drive letter off for windows (with forwardslashes)" do
- @backup.should_receive(:path).and_return('c:/a/b/c.txt')
- @backup.send(:backup_filename).should =~ %r|^/a/b/c.txt.chef-\d{14}.\d{6}$|
+ 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
- @backup.should_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
- @backup.send(:backup_path).should =~ %r|^/a/b/c.txt.chef-\d{14}.\d{6}$|
+ 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
- @backup.should_receive(:path).and_return('/a/b/c.txt')
+ expect(@backup).to receive(:path).and_return('/a/b/c.txt')
Chef::Config[:file_backup_path] = '/backupdir'
- @backup.send(:backup_path).should =~ %r|^/backupdir[\\/]+a/b/c.txt.chef-\d{14}.\d{6}$|
+ expect(@backup.send(:backup_path)).to match(%r|^/backupdir[\\/]+a/b/c.txt.chef-\d{14}.\d{6}$|)
end
it "uses the configured Chef::Config[:file_backup_path] and strips the drive on windows" do
- @backup.should_receive(:path).and_return('c:\\a\\b\\c.txt')
+ expect(@backup).to receive(:path).and_return('c:\\a\\b\\c.txt')
Chef::Config[:file_backup_path] = 'c:\backupdir'
- @backup.send(:backup_path).should =~ %r|^c:\\backupdir[\\/]+a\\b\\c.txt.chef-\d{14}.\d{6}$|
+ expect(@backup.send(:backup_path)).to match(%r|^c:\\backupdir[\\/]+a\\b\\c.txt.chef-\d{14}.\d{6}$|)
end
end
diff --git a/spec/unit/util/diff_spec.rb b/spec/unit/util/diff_spec.rb
index 947ce1d5aa..ea226f1c04 100644
--- a/spec/unit/util/diff_spec.rb
+++ b/spec/unit/util/diff_spec.rb
@@ -122,7 +122,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -135,7 +135,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -187,7 +187,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -213,7 +213,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -251,7 +251,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -290,7 +290,7 @@ shared_examples_for "a diff util" do
new_tempfile.close
end
it "calling for_output should return a valid diff" do
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a utf-8 string" do
expect(differ.for_reporting.encoding).to equal(Encoding::UTF_8)
@@ -349,12 +349,12 @@ shared_examples_for "a diff util" do
end
it "calling for_output should return a unified diff" do
- differ.for_output.size.should eql(5)
- differ.for_output.join("\\n").should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_output.size).to eql(5)
+ expect(differ.for_output.join("\\n")).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
it "calling for_reporting should return a unified diff" do
- differ.for_reporting.should match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
+ expect(differ.for_reporting).to match(/\A--- .*\\n\+\+\+ .*\\n@@/m)
end
describe "when the diff output is too long" do
@@ -383,7 +383,7 @@ shared_examples_for "a diff util" do
it "should identify zero-length files as text" do
Tempfile.open("chef-util-diff-spec") do |file|
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -391,7 +391,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(plain_ascii)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -399,7 +399,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write("This is a binary file.\0")
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -407,7 +407,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write("This is a binary file.\nNo Really\nit is\0")
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -426,7 +426,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(plain_ascii)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -434,7 +434,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(utf_8)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -442,7 +442,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(latin_1)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -450,7 +450,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(shift_jis)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -471,7 +471,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(plain_ascii)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -479,7 +479,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(utf_8)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -487,7 +487,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(latin_1)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
@@ -495,7 +495,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(shift_jis)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
end
@@ -515,14 +515,14 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(plain_ascii)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
it "should identify UTF-8 that is invalid Shift-JIS as binary" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(utf_8)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -530,7 +530,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(latin_1)
file.close
- differ.send(:is_binary?, file.path).should be_true
+ expect(differ.send(:is_binary?, file.path)).to be_truthy
end
end
@@ -538,7 +538,7 @@ shared_examples_for "a diff util" do
Tempfile.open("chef-util-diff-spec") do |file|
file.write(shift_jis)
file.close
- differ.send(:is_binary?, file.path).should be_false
+ expect(differ.send(:is_binary?, file.path)).to be_falsey
end
end
diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb
index 03f3ffe25c..c39c949991 100644
--- a/spec/unit/util/dsc/configuration_generator_spec.rb
+++ b/spec/unit/util/dsc/configuration_generator_spec.rb
@@ -51,9 +51,9 @@ describe Chef::Util::DSC::ConfigurationGenerator 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')
- merged.should include(:flag)
- merged[:flag].should eql('a')
- merged.should include(:outputpath)
+ expect(merged).to include(:flag)
+ expect(merged[:flag]).to eql('a')
+ expect(merged).to include(:outputpath)
end
it 'should raise an ArgumentError if you try to override outputpath' do
@@ -70,16 +70,16 @@ describe Chef::Util::DSC::ConfigurationGenerator do
it 'should be case insensitive to switches that are allowed' do
merged = conf_man.send(:get_merged_configuration_flags!, {'FLAG' => 'a'}, 'hello')
- merged.should include(:flag)
+ 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')
- merged.should include(:flag)
- merged[:flag].should eql('a')
- merged.should include(:outputpath)
+ expect(merged).to include(:flag)
+ expect(merged[:flag]).to eql('a')
+ expect(merged).to include(:outputpath)
end
it 'should raise an ArgumentError if you try to override outputpath' do
@@ -96,21 +96,21 @@ describe Chef::Util::DSC::ConfigurationGenerator do
it 'should be case insensitive to switches that are allowed' do
merged = conf_man.send(:get_merged_configuration_flags!, {:FLAG => 'a'}, 'hello')
- merged.should include(:flag)
+ 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')
- merged.should include(:outputpath)
- merged.length.should eql(1)
+ 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')
- merged.should include(:outputpath)
- merged.length.should eql(1)
+ expect(merged).to include(:outputpath)
+ expect(merged.length).to eql(1)
end
end
@@ -165,7 +165,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do
found_configuration = true
end
end
- expect(found_configuration).to be_true
+ expect(found_configuration).to be_truthy
end
end
end
diff --git a/spec/unit/util/dsc/lcm_output_parser_spec.rb b/spec/unit/util/dsc/lcm_output_parser_spec.rb
index 23a3dbd3ec..ba4f40c4f7 100644
--- a/spec/unit/util/dsc/lcm_output_parser_spec.rb
+++ b/spec/unit/util/dsc/lcm_output_parser_spec.rb
@@ -21,11 +21,11 @@ require 'chef/util/dsc/lcm_output_parser'
describe Chef::Util::DSC::LocalConfigurationManager::Parser do
context 'empty input parameter' do
it 'returns an empty array for a 0 length string' do
- Chef::Util::DSC::LocalConfigurationManager::Parser::parse('').should be_empty
+ expect(Chef::Util::DSC::LocalConfigurationManager::Parser::parse('')).to be_empty
end
it 'returns an empty array for a nil input' do
- Chef::Util::DSC::LocalConfigurationManager::Parser::parse('').should be_empty
+ expect(Chef::Util::DSC::LocalConfigurationManager::Parser::parse('')).to be_empty
end
end
@@ -35,7 +35,7 @@ describe Chef::Util::DSC::LocalConfigurationManager::Parser do
logtype: [machinename]: LCM: [ Start Set ]
logtype: [machinename]: LCM: [ End Set ]
EOF
- Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str).should be_empty
+ expect(Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)).to be_empty
end
it 'returns a single resource when only 1 logged with the correct name' do
@@ -46,8 +46,8 @@ logtype: [machinename]: LCM: [ End Resource ] [name]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources.length.should eq(1)
- resources[0].name.should eq('[name]')
+ expect(resources.length).to eq(1)
+ expect(resources[0].name).to eq('[name]')
end
it 'identifies when a resource changes the state of the system' do
@@ -60,7 +60,7 @@ logtype: [machinename]: LCM: [ End Resource ] [name]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].changes_state?.should be_true
+ expect(resources[0].changes_state?).to be_truthy
end
it 'preserves the log provided for how the system changed the state' do
@@ -74,7 +74,7 @@ logtype: [machinename]: LCM: [ End Resource ] [name]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].change_log.should match_array(["[name]","[message]","[name]"])
+ expect(resources[0].change_log).to match_array(["[name]","[message]","[name]"])
end
it 'should return false for changes_state?' do
@@ -86,7 +86,7 @@ logtype: [machinename]: LCM: [ End Resource ] [name]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].changes_state?.should be_false
+ expect(resources[0].changes_state?).to be_falsey
end
it 'should return an empty array for change_log if changes_state? is false' do
@@ -98,7 +98,7 @@ logtype: [machinename]: LCM: [ End Resource ] [name]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].change_log.should be_empty
+ expect(resources[0].change_log).to be_empty
end
end
@@ -120,8 +120,8 @@ logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].changes_state?.should be_false
- resources[1].changes_state?.should be_true
+ expect(resources[0].changes_state?).to be_falsey
+ 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
@@ -141,8 +141,8 @@ logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].changes_state?.should be_false
- resources[1].changes_state?.should be_true
+ expect(resources[0].changes_state?).to be_falsey
+ 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
@@ -160,10 +160,10 @@ logtype: [machinename]: LCM: [ End Resource ]
logtype: [machinename]: LCM: [ End Set ]
EOF
resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str)
- resources[0].changes_state?.should be_true
- resources[0].name.should eql('[name]')
- resources[1].changes_state?.should be_true
- resources[1].name.should eql('[name2]')
+ expect(resources[0].changes_state?).to be_truthy
+ expect(resources[0].name).to eql('[name]')
+ expect(resources[1].changes_state?).to be_truthy
+ 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 eb27e9e94e..009c667c87 100644
--- a/spec/unit/util/dsc/local_configuration_manager_spec.rb
+++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb
@@ -78,7 +78,7 @@ EOH
let(:lcm_cmdlet_success) { false }
it 'returns true when passed to #whatif_not_supported?' do
- expect(lcm.send(:whatif_not_supported?, no_whatif_lcm_output)).to be_true
+ 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
diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb
index 06370f7de0..968302df17 100644
--- a/spec/unit/util/editor_spec.rb
+++ b/spec/unit/util/editor_spec.rb
@@ -22,7 +22,7 @@ describe Chef::Util::Editor do
context 'when there is no match' do
subject(:execute) { editor.append_line_after('missing', 'new') }
- it('returns the number of added lines') { should be == 0 }
+ 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
@@ -31,7 +31,7 @@ describe Chef::Util::Editor do
context 'when there is a match' do
subject(:execute) { editor.append_line_after('two', 'new') }
- it('returns the number of added lines') { should be == 2 }
+ 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']
@@ -48,7 +48,7 @@ describe Chef::Util::Editor do
context 'when there is no match' do
subject(:execute) { editor.append_line_if_missing('missing', 'new') }
- it('returns the number of added lines') { should be == 1 }
+ 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']
@@ -58,7 +58,7 @@ describe Chef::Util::Editor do
context 'when there is a match' do
subject(:execute) { editor.append_line_if_missing('one', 'new') }
- it('returns the number of added lines') { should be == 0 }
+ 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
@@ -74,7 +74,7 @@ describe Chef::Util::Editor do
context 'when there is no match' do
subject(:execute) { editor.remove_lines('missing') }
- it('returns the number of removed lines') { should be == 0 }
+ 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
@@ -83,7 +83,7 @@ describe Chef::Util::Editor do
context 'when there is a match' do
subject(:execute) { editor.remove_lines('two') }
- it('returns the number of removed lines') { should be == 2 }
+ 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']
@@ -100,7 +100,7 @@ describe Chef::Util::Editor do
context 'when there is no match' do
subject(:execute) { editor.replace('missing', 'new') }
- it('returns the number of changed lines') { should be == 0 }
+ 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
@@ -109,7 +109,7 @@ describe Chef::Util::Editor do
context 'when there is a match' do
subject(:execute) { editor.replace('two', 'new') }
- it('returns the number of changed lines') { should be == 2 }
+ 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']
@@ -127,7 +127,7 @@ describe Chef::Util::Editor do
context 'when there is no match' do
subject(:execute) { editor.replace_lines('missing', 'new') }
- it('returns the number of changed lines') { should be == 0 }
+ 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
@@ -136,7 +136,7 @@ describe Chef::Util::Editor do
context 'when there is a match' do
subject(:execute) { editor.replace_lines('two', 'new') }
- it('returns the number of replaced lines') { should be == 2 }
+ 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']
diff --git a/spec/unit/util/file_edit_spec.rb b/spec/unit/util/file_edit_spec.rb
index 139b29d9ce..b99cf2f426 100644
--- a/spec/unit/util/file_edit_spec.rb
+++ b/spec/unit/util/file_edit_spec.rb
@@ -135,21 +135,21 @@ twice
describe "search_file_replace" do
it "should accept regex passed in as a string (not Regexp object) and replace the match if there is one" do
fedit.search_file_replace("localhost", "replacement")
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(localhost_replaced)
end
it "should accept regex passed in as a Regexp object and replace the match if there is one" do
fedit.search_file_replace(/localhost/, "replacement")
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(localhost_replaced)
end
it "should do nothing if there isn't a match" do
fedit.search_file_replace(/pattern/, "replacement")
- fedit.unwritten_changes?.should be_false
+ expect(fedit.unwritten_changes?).to be_falsey
fedit.write_file
expect(edited_file_contents).to eq(starting_content)
end
@@ -158,7 +158,7 @@ twice
describe "search_file_replace_line" do
it "should search for match and replace the whole line" do
fedit.search_file_replace_line(/localhost/, "replacement line")
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(localhost_line_replaced)
end
@@ -167,7 +167,7 @@ twice
describe "search_file_delete" do
it "should search for match and delete the match" do
fedit.search_file_delete(/localhost/)
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(localhost_deleted)
end
@@ -176,7 +176,7 @@ twice
describe "search_file_delete_line" do
it "should search for match and delete the matching line" do
fedit.search_file_delete_line(/localhost/)
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(localhost_line_deleted)
end
@@ -185,7 +185,7 @@ twice
describe "insert_line_after_match" do
it "should search for match and insert the given line after the matching line" do
fedit.insert_line_after_match(/localhost/, "new line inserted")
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(append_after_all_localhost)
end
@@ -194,14 +194,14 @@ twice
describe "insert_line_if_no_match" do
it "should search for match and insert the given line if no line match" do
fedit.insert_line_if_no_match(/pattern/, "new line inserted")
- fedit.unwritten_changes?.should be_true
+ expect(fedit.unwritten_changes?).to be_truthy
fedit.write_file
expect(edited_file_contents).to eq(append_after_content)
end
it "should do nothing if there is a match" do
fedit.insert_line_if_no_match(/localhost/, "replacement")
- fedit.unwritten_changes?.should be_false
+ expect(fedit.unwritten_changes?).to be_falsey
fedit.write_file
expect(edited_file_contents).to eq(starting_content)
end
@@ -218,7 +218,7 @@ twice
it "should return true if a file got edited" do
fedit.insert_line_if_no_match(/pattern/, "new line inserted")
fedit.write_file
- expect(fedit.file_edited?).to be_true
+ expect(fedit.file_edited?).to be_truthy
end
end
end
diff --git a/spec/unit/util/path_helper_spec.rb b/spec/unit/util/path_helper_spec.rb
index 1d97efc607..4df4b9b1ff 100644
--- a/spec/unit/util/path_helper_spec.rb
+++ b/spec/unit/util/path_helper_spec.rb
@@ -25,81 +25,81 @@ describe Chef::Util::PathHelper do
[ false, true ].each do |is_windows|
context "on #{is_windows ? "windows" : "unix"}" do
before(:each) do
- Chef::Platform.stub(:windows?).and_return(is_windows)
+ allow(Chef::Platform).to receive(:windows?).and_return(is_windows)
end
describe "join" do
it "joins components when some end with separators" do
expected = PathHelper.cleanpath("/foo/bar/baz")
expected = "C:#{expected}" if is_windows
- PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar", "baz").should == expected
+ expect(PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar", "baz")).to eq(expected)
end
it "joins components when some end and start with separators" do
expected = PathHelper.cleanpath("/foo/bar/baz")
expected = "C:#{expected}" if is_windows
- PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar/", "/baz").should == expected
+ expect(PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar/", "/baz")).to eq(expected)
end
it "joins components that don't end in separators" do
expected = PathHelper.cleanpath("/foo/bar/baz")
expected = "C:#{expected}" if is_windows
- PathHelper.join(is_windows ? 'C:\\foo' : "/foo", "bar", "baz").should == expected
+ expect(PathHelper.join(is_windows ? 'C:\\foo' : "/foo", "bar", "baz")).to eq(expected)
end
it "joins starting with '' resolve to absolute paths" do
- PathHelper.join('', 'a', 'b').should == "#{PathHelper.path_separator}a#{PathHelper.path_separator}b"
+ expect(PathHelper.join('', 'a', 'b')).to eq("#{PathHelper.path_separator}a#{PathHelper.path_separator}b")
end
it "joins ending with '' add a / to the end" do
- PathHelper.join('a', 'b', '').should == "a#{PathHelper.path_separator}b#{PathHelper.path_separator}"
+ expect(PathHelper.join('a', 'b', '')).to eq("a#{PathHelper.path_separator}b#{PathHelper.path_separator}")
end
if is_windows
it "joins components on Windows when some end with unix separators" do
- PathHelper.join('C:\\foo/', "bar", "baz").should == 'C:\\foo\\bar\\baz'
+ expect(PathHelper.join('C:\\foo/', "bar", "baz")).to eq('C:\\foo\\bar\\baz')
end
end
end
if is_windows
it "path_separator is \\" do
- PathHelper.path_separator.should == '\\'
+ expect(PathHelper.path_separator).to eq('\\')
end
else
it "path_separator is /" do
- PathHelper.path_separator.should == '/'
+ expect(PathHelper.path_separator).to eq('/')
end
end
if is_windows
it "cleanpath changes slashes into backslashes and leaves backslashes alone" do
- PathHelper.cleanpath('/a/b\\c/d/').should == '\\a\\b\\c\\d'
+ expect(PathHelper.cleanpath('/a/b\\c/d/')).to eq('\\a\\b\\c\\d')
end
it "cleanpath does not remove leading double backslash" do
- PathHelper.cleanpath('\\\\a/b\\c/d/').should == '\\\\a\\b\\c\\d'
+ expect(PathHelper.cleanpath('\\\\a/b\\c/d/')).to eq('\\\\a\\b\\c\\d')
end
else
it "cleanpath removes extra slashes alone" do
- PathHelper.cleanpath('/a///b/c/d/').should == '/a/b/c/d'
+ expect(PathHelper.cleanpath('/a///b/c/d/')).to eq('/a/b/c/d')
end
end
describe "dirname" do
it "dirname('abc') is '.'" do
- PathHelper.dirname('abc').should == '.'
+ expect(PathHelper.dirname('abc')).to eq('.')
end
it "dirname('/') is '/'" do
- PathHelper.dirname(PathHelper.path_separator).should == PathHelper.path_separator
+ expect(PathHelper.dirname(PathHelper.path_separator)).to eq(PathHelper.path_separator)
end
it "dirname('a/b/c') is 'a/b'" do
- PathHelper.dirname(PathHelper.join('a', 'b', 'c')).should == PathHelper.join('a', 'b')
+ expect(PathHelper.dirname(PathHelper.join('a', 'b', 'c'))).to eq(PathHelper.join('a', 'b'))
end
it "dirname('a/b/c/') is 'a/b'" do
- PathHelper.dirname(PathHelper.join('a', 'b', 'c', '')).should == PathHelper.join('a', 'b')
+ expect(PathHelper.dirname(PathHelper.join('a', 'b', 'c', ''))).to eq(PathHelper.join('a', 'b'))
end
it "dirname('/a/b/c') is '/a/b'" do
- PathHelper.dirname(PathHelper.join('', 'a', 'b', 'c')).should == PathHelper.join('', 'a', 'b')
+ expect(PathHelper.dirname(PathHelper.join('', 'a', 'b', 'c'))).to eq(PathHelper.join('', 'a', 'b'))
end
end
end
@@ -109,9 +109,9 @@ describe Chef::Util::PathHelper do
context "on windows" do
before(:each) do
# pass by default
- Chef::Platform.stub(:windows?).and_return(true)
- PathHelper.stub(:printable?).and_return(true)
- PathHelper.stub(:windows_max_length_exceeded?).and_return(false)
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
+ allow(PathHelper).to receive(:printable?).and_return(true)
+ allow(PathHelper).to receive(:windows_max_length_exceeded?).and_return(false)
end
it "returns the path if the path passes the tests" do
@@ -123,14 +123,14 @@ describe Chef::Util::PathHelper do
end
it "raises an error if the path has invalid characters" do
- PathHelper.stub(:printable?).and_return(false)
+ allow(PathHelper).to receive(:printable?).and_return(false)
expect { PathHelper.validate_path("Newline!\n") }.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "Adds the \\\\?\\ prefix if the path exceeds MAX_LENGTH and does not have it" do
long_path = "C:\\" + "a" * 250 + "\\" + "b" * 250
prefixed_long_path = "\\\\?\\" + long_path
- PathHelper.stub(:windows_max_length_exceeded?).and_return(true)
+ allow(PathHelper).to receive(:windows_max_length_exceeded?).and_return(true)
expect(PathHelper.validate_path(long_path)).to eql(prefixed_long_path)
end
end
@@ -138,38 +138,38 @@ describe Chef::Util::PathHelper do
describe "windows_max_length_exceeded?" do
it "returns true if the path is too long (259 + NUL) for the API" do
- expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_true
+ expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_truthy
end
it "returns false if the path is not too long (259 + NUL) for the standard API" do
- expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_false
+ expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_falsey
end
it "returns false if the path is over 259 characters but uses the \\\\?\\ prefix" do
- expect(PathHelper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_false
+ expect(PathHelper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_falsey
end
end
describe "printable?" do
it "returns true if the string contains no non-printable characters" do
- expect(PathHelper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_true
+ expect(PathHelper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_truthy
end
it "returns true when given 'abc' in unicode" do
- expect(PathHelper.printable?("\u0061\u0062\u0063")).to be_true
+ expect(PathHelper.printable?("\u0061\u0062\u0063")).to be_truthy
end
it "returns true when given japanese unicode" do
- expect(PathHelper.printable?("\uff86\uff87\uff88")).to be_true
+ expect(PathHelper.printable?("\uff86\uff87\uff88")).to be_truthy
end
it "returns false if the string contains a non-printable character" do
- expect(PathHelper.printable?("\my files\work\notes.txt")).to be_false
+ expect(PathHelper.printable?("\my files\work\notes.txt")).to be_falsey
end
# This isn't necessarily a requirement, but here to be explicit about functionality.
it "returns false if the string contains a newline or tab" do
- expect(PathHelper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_false
+ expect(PathHelper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_falsey
end
end
@@ -205,15 +205,15 @@ describe Chef::Util::PathHelper do
describe "paths_eql?" do
it "returns true if the paths are the same" do
- PathHelper.stub(:canonical_path).with("bandit").and_return("c:/bandit/bandit")
- PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
- expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_true
+ allow(PathHelper).to receive(:canonical_path).with("bandit").and_return("c:/bandit/bandit")
+ allow(PathHelper).to receive(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
+ expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_truthy
end
it "returns false if the paths are different" do
- PathHelper.stub(:canonical_path).with("bandit").and_return("c:/Bo/Bandit")
- PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
- expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_false
+ allow(PathHelper).to receive(:canonical_path).with("bandit").and_return("c:/Bo/Bandit")
+ allow(PathHelper).to receive(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
+ expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_falsey
end
end
diff --git a/spec/unit/util/powershell/cmdlet_spec.rb b/spec/unit/util/powershell/cmdlet_spec.rb
index a964f607c8..5ddf9282c4 100644
--- a/spec/unit/util/powershell/cmdlet_spec.rb
+++ b/spec/unit/util/powershell/cmdlet_spec.rb
@@ -51,18 +51,18 @@ describe Chef::Util::Powershell::Cmdlet do
# Is this list really complete?
%w{` " # '}.each do |c|
it "escapse #{c}" do
- @cmdlet.send(:escape_parameter_value, "stuff #{c}").should eql("stuff `#{c}")
+ expect(@cmdlet.send(:escape_parameter_value, "stuff #{c}")).to eql("stuff `#{c}")
end
end
it 'does not do anything to a string without special characters' do
- @cmdlet.send(:escape_parameter_value, 'stuff').should eql('stuff')
+ expect(@cmdlet.send(:escape_parameter_value, 'stuff')).to eql('stuff')
end
end
describe '#escape_string_parameter_value' do
it "surrounds a string with ''" do
- @cmdlet.send(:escape_string_parameter_value, 'stuff').should eql("'stuff'")
+ expect(@cmdlet.send(:escape_string_parameter_value, 'stuff')).to eql("'stuff'")
end
end
@@ -80,27 +80,27 @@ describe Chef::Util::Powershell::Cmdlet do
end
it 'ignores switches with a false value' do
- @cmdlet.send(:command_switches_string, {foo: false}).should eql('')
+ expect(@cmdlet.send(:command_switches_string, {foo: false})).to eql('')
end
it 'should correctly handle a value type of string' do
- @cmdlet.send(:command_switches_string, {foo: 'bar'}).should eql("-foo 'bar'")
+ 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
- @cmdlet.send(:command_switches_string, {foo: ''}).should eql("-foo ''")
+ expect(@cmdlet.send(:command_switches_string, {foo: ''})).to eql("-foo ''")
end
it 'should not quote integers' do
- @cmdlet.send(:command_switches_string, {foo: 1}).should eql("-foo 1")
+ expect(@cmdlet.send(:command_switches_string, {foo: 1})).to eql("-foo 1")
end
it 'should not quote floats' do
- @cmdlet.send(:command_switches_string, {foo: 1.0}).should eql("-foo 1.0")
+ 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
- @cmdlet.send(:command_switches_string, {foo: true}).should eql("-foo")
+ expect(@cmdlet.send(:command_switches_string, {foo: true})).to eql("-foo")
end
end
end
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index 53faba3db3..0ed138c7bc 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -44,17 +44,17 @@ describe Chef::Util::Selinux do
expected_paths.each do |bin_path|
selinux_path = File.join(bin_path, "selinuxenabled")
- File.should_receive(:executable?).with(selinux_path).and_return(false)
+ expect(File).to receive(:executable?).with(selinux_path).and_return(false)
end
- @test_instance.selinux_enabled?.should be_false
+ expect(@test_instance.selinux_enabled?).to be_falsey
end
describe "when selinuxenabled binary exists" do
before do
@selinux_enabled_path = File.join("/sbin", "selinuxenabled")
- File.stub(:executable?) do |file_path|
- file_path.end_with?("selinuxenabled").should be_true
+ allow(File).to receive(:executable?) do |file_path|
+ expect(file_path.end_with?("selinuxenabled")).to be_truthy
file_path == @selinux_enabled_path
end
end
@@ -62,54 +62,54 @@ describe Chef::Util::Selinux do
describe "when selinux is enabled" do
before do
cmd_result = double("Cmd Result", :exitstatus => 0)
- @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
+ expect(@test_instance).to receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
end
it "should report selinux is enabled" do
- @test_instance.selinux_enabled?.should be_true
+ expect(@test_instance.selinux_enabled?).to be_truthy
# should check the file system only once for multiple calls
- @test_instance.selinux_enabled?.should be_true
+ expect(@test_instance.selinux_enabled?).to be_truthy
end
end
describe "when selinux is disabled" do
before do
cmd_result = double("Cmd Result", :exitstatus => 1)
- @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
+ expect(@test_instance).to receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
end
it "should report selinux is disabled" do
- @test_instance.selinux_enabled?.should be_false
+ expect(@test_instance.selinux_enabled?).to be_falsey
# should check the file system only once for multiple calls
- @test_instance.selinux_enabled?.should be_false
+ expect(@test_instance.selinux_enabled?).to be_falsey
end
end
describe "when selinux gives an unexpected status" do
before do
cmd_result = double("Cmd Result", :exitstatus => 101)
- @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
+ expect(@test_instance).to receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result)
end
it "should throw an error" do
- lambda {@test_instance.selinux_enabled?}.should raise_error(RuntimeError)
+ expect {@test_instance.selinux_enabled?}.to raise_error(RuntimeError)
end
end
end
describe "when selinuxenabled binary doesn't exist" do
before do
- File.stub(:executable?) do |file_path|
- file_path.end_with?("selinuxenabled").should be_true
+ allow(File).to receive(:executable?) do |file_path|
+ expect(file_path.end_with?("selinuxenabled")).to be_truthy
false
end
end
it "should report selinux is disabled" do
- @test_instance.selinux_enabled?.should be_false
+ expect(@test_instance.selinux_enabled?).to be_falsey
# should check the file system only once for multiple calls
- File.should_not_receive(:executable?)
- @test_instance.selinux_enabled?.should be_false
+ expect(File).not_to receive(:executable?)
+ expect(@test_instance.selinux_enabled?).to be_falsey
end
end
@@ -118,53 +118,53 @@ describe Chef::Util::Selinux do
before do
@restorecon_enabled_path = File.join("/sbin", "restorecon")
- File.stub(:executable?) do |file_path|
- file_path.end_with?("restorecon").should be_true
+ allow(File).to receive(:executable?) do |file_path|
+ expect(file_path.end_with?("restorecon")).to be_truthy
file_path == @restorecon_enabled_path
end
end
it "should call restorecon non-recursive by default" do
restorecon_command = "#{@restorecon_enabled_path} -R \"#{path}\""
- @test_instance.should_receive(:shell_out!).twice.with(restorecon_command)
+ expect(@test_instance).to receive(:shell_out!).twice.with(restorecon_command)
@test_instance.restore_security_context(path)
- File.should_not_receive(:executable?)
+ expect(File).not_to receive(:executable?)
@test_instance.restore_security_context(path)
end
it "should call restorecon recursive when recursive is set" do
restorecon_command = "#{@restorecon_enabled_path} -R -r \"#{path}\""
- @test_instance.should_receive(:shell_out!).twice.with(restorecon_command)
+ expect(@test_instance).to receive(:shell_out!).twice.with(restorecon_command)
@test_instance.restore_security_context(path, true)
- File.should_not_receive(:executable?)
+ expect(File).not_to receive(:executable?)
@test_instance.restore_security_context(path, true)
end
it "should call restorecon non-recursive when recursive is not set" do
restorecon_command = "#{@restorecon_enabled_path} -R \"#{path}\""
- @test_instance.should_receive(:shell_out!).twice.with(restorecon_command)
+ expect(@test_instance).to receive(:shell_out!).twice.with(restorecon_command)
@test_instance.restore_security_context(path)
- File.should_not_receive(:executable?)
+ expect(File).not_to receive(:executable?)
@test_instance.restore_security_context(path)
end
describe "when restorecon doesn't exist on the system" do
before do
- File.stub(:executable?) do |file_path|
- file_path.end_with?("restorecon").should be_true
+ allow(File).to receive(:executable?) do |file_path|
+ expect(file_path.end_with?("restorecon")).to be_truthy
false
end
end
it "should log a warning message" do
log = [ ]
- Chef::Log.stub(:warn) do |message|
+ allow(Chef::Log).to receive(:warn) do |message|
log << message
end
@test_instance.restore_security_context(path)
- log.should_not be_empty
- File.should_not_receive(:executable?)
+ expect(log).not_to be_empty
+ expect(File).not_to receive(:executable?)
@test_instance.restore_security_context(path)
end
end
diff --git a/spec/unit/util/threaded_job_queue_spec.rb b/spec/unit/util/threaded_job_queue_spec.rb
index a199937639..22626328be 100644
--- a/spec/unit/util/threaded_job_queue_spec.rb
+++ b/spec/unit/util/threaded_job_queue_spec.rb
@@ -23,8 +23,8 @@ describe Chef::Util::ThreadedJobQueue do
it "should pass mutex to jobs with an arity of 1" do
job = double()
- job.should_receive(:arity).at_least(:once).and_return(1)
- job.should_receive(:call).exactly(5).times.with(an_instance_of(Mutex))
+ expect(job).to receive(:arity).at_least(:once).and_return(1)
+ expect(job).to receive(:call).exactly(5).times.with(an_instance_of(Mutex))
5.times { queue << job }
queue.process
@@ -32,20 +32,20 @@ describe Chef::Util::ThreadedJobQueue do
it "should pass nothing to jobs with an arity of 0" do
job = double()
- job.should_receive(:arity).at_least(:once).and_return(0)
- job.should_receive(:call).exactly(5).times.with(no_args)
+ expect(job).to receive(:arity).at_least(:once).and_return(0)
+ expect(job).to receive(:call).exactly(5).times.with(no_args)
5.times { queue << job }
queue.process
end
it "should use specified number of threads" do
- Thread.should_receive(:new).exactly(7).times.and_call_original
+ expect(Thread).to receive(:new).exactly(7).times.and_call_original
queue.process(7)
end
it "should propagate exceptions to the main thread" do
queue << lambda { raise WorkerThreadError }
- lambda { queue.process }.should raise_error(WorkerThreadError)
+ expect { queue.process }.to raise_error(WorkerThreadError)
end
end