summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/mixin/shell_out_spec.rb4
-rw-r--r--spec/functional/provider/whyrun_safe_ruby_block_spec.rb51
-rw-r--r--spec/functional/rebooter_spec.rb105
-rw-r--r--spec/functional/resource/deploy_revision_spec.rb4
-rw-r--r--spec/functional/resource/file_spec.rb29
-rw-r--r--spec/functional/resource/link_spec.rb32
-rw-r--r--spec/functional/resource/reboot_spec.rb103
-rw-r--r--spec/unit/application/apply.rb12
-rw-r--r--spec/unit/dsl/reboot_pending_spec.rb8
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb15
-rw-r--r--spec/unit/mixin/shell_out_spec.rb198
-rw-r--r--spec/unit/provider/ifconfig/debian_spec.rb28
-rw-r--r--spec/unit/provider/ifconfig/redhat_spec.rb30
-rw-r--r--spec/unit/provider/ifconfig_spec.rb6
-rw-r--r--spec/unit/provider/link_spec.rb10
-rw-r--r--spec/unit/provider/package/aix_spec.rb22
-rw-r--r--spec/unit/provider/package/ips_spec.rb29
-rw-r--r--spec/unit/provider/package/macports_spec.rb24
-rw-r--r--spec/unit/provider/package/pacman_spec.rb16
-rw-r--r--spec/unit/provider/package/portage_spec.rb20
-rw-r--r--spec/unit/provider/package/rpm_spec.rb29
-rw-r--r--spec/unit/provider/package/solaris_spec.rb21
-rw-r--r--spec/unit/provider/service/arch_service_spec.rb22
-rw-r--r--spec/unit/provider/service/debian_service_spec.rb2
-rw-r--r--spec/unit/provider/service/freebsd_service_spec.rb12
-rw-r--r--spec/unit/provider/service/gentoo_service_spec.rb4
-rw-r--r--spec/unit/provider/service/init_service_spec.rb20
-rw-r--r--spec/unit/provider/service/insserv_service_spec.rb7
-rw-r--r--spec/unit/provider/service/invokercd_service_spec.rb17
-rw-r--r--spec/unit/provider/service/macosx_spec.rb10
-rw-r--r--spec/unit/provider/service/simple_service_spec.rb8
-rw-r--r--spec/unit/provider/service/solaris_smf_service_spec.rb4
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb40
-rw-r--r--spec/unit/provider/service/upstart_service_spec.rb32
-rw-r--r--spec/unit/provider/subversion_spec.rb11
-rw-r--r--spec/unit/provider/whyrun_safe_ruby_block_spec.rb4
-rw-r--r--spec/unit/run_context_spec.rb15
-rw-r--r--spec/unit/workstation_config_loader_spec.rb10
38 files changed, 665 insertions, 349 deletions
diff --git a/spec/functional/mixin/shell_out_spec.rb b/spec/functional/mixin/shell_out_spec.rb
index 92492fcf6f..35e5b30eae 100644
--- a/spec/functional/mixin/shell_out_spec.rb
+++ b/spec/functional/mixin/shell_out_spec.rb
@@ -29,7 +29,7 @@ describe Chef::Mixin::ShellOut do
shell_out_with_systems_locale('echo $LC_ALL')
end
- cmd.stdout.chomp.should match_environment_variable('LC_ALL')
+ expect(cmd.stdout.chomp).to match_environment_variable('LC_ALL')
end
end
@@ -41,7 +41,7 @@ describe Chef::Mixin::ShellOut do
shell_out_with_systems_locale('echo $LC_ALL', :environment => {'LC_ALL' => 'POSIX'})
end
- cmd.stdout.chomp.should eq 'POSIX'
+ expect(cmd.stdout.chomp).to eq 'POSIX'
end
end
end
diff --git a/spec/functional/provider/whyrun_safe_ruby_block_spec.rb b/spec/functional/provider/whyrun_safe_ruby_block_spec.rb
new file mode 100644
index 0000000000..150d46d384
--- /dev/null
+++ b/spec/functional/provider/whyrun_safe_ruby_block_spec.rb
@@ -0,0 +1,51 @@
+#
+# Author:: Serdar Sutay (<serdar@opscode.com>)
+# Copyright:: Copyright (c) 2014 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Resource::WhyrunSafeRubyBlock do
+ let(:node) { Chef::Node.new }
+
+ let(:run_context) {
+ events = Chef::EventDispatch::Dispatcher.new
+ Chef::RunContext.new(node, {}, events)
+ }
+
+ before do
+ $evil_global_evil_laugh = :wahwah
+ Chef::Config[:why_run] = true
+ end
+
+ after do
+ Chef::Config[:why_run] = false
+ end
+
+ describe "when testing the resource" do
+ let(:new_resource) do
+ r = Chef::Resource::WhyrunSafeRubyBlock.new("reload all", run_context)
+ r.block { $evil_global_evil_laugh = :mwahahaha }
+ r
+ end
+
+ it "updates the evil laugh, even in why-run mode" do
+ new_resource.run_action(new_resource.action)
+ $evil_global_evil_laugh.should == :mwahahaha
+ new_resource.should be_updated
+ end
+ end
+end
diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb
new file mode 100644
index 0000000000..8006580d5c
--- /dev/null
+++ b/spec/functional/rebooter_spec.rb
@@ -0,0 +1,105 @@
+#
+# Author:: Chris Doherty <cdoherty@getchef.com>)
+# Copyright:: Copyright (c) 2014 Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Platform::Rebooter do
+
+ let(:reboot_info) do
+ {
+ :delay_mins => 5,
+ :requested_by => "reboot resource functional test",
+ :reason => "rebooter spec test"
+ }
+ end
+
+ def create_resource
+ resource = Chef::Resource::Reboot.new(expected[:requested_by], run_context)
+ resource.delay_mins(expected[:delay_mins])
+ resource.reason(expected[:reason])
+ resource
+ end
+
+ let(:run_context) do
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ Chef::RunContext.new(node, {}, events)
+ end
+
+ let(:expected) do
+ {
+ :windows => 'shutdown /r /t 5 /c "rebooter spec test"',
+ :linux => 'shutdown -r +5 "rebooter spec test"'
+ }
+ end
+
+ let(:rebooter) { Chef::Platform::Rebooter }
+
+ describe '#reboot_if_needed!' do
+
+ it 'should not call #shell_out! when reboot has not been requested' do
+ expect(rebooter).to receive(:shell_out!).exactly(0).times
+ expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
+ rebooter.reboot_if_needed!(run_context.node)
+ end
+
+ describe 'calling #shell_out! to reboot' do
+
+ before(:each) do
+ run_context.request_reboot(reboot_info)
+ end
+
+ after(:each) do
+ run_context.cancel_reboot
+ end
+
+ shared_context 'test a reboot method' do
+ def test_rebooter_method(method_sym, is_windows, expected_reboot_str)
+ Chef::Platform.stub(:windows?).and_return(is_windows)
+ expect(rebooter).to receive(:shell_out!).once.with(expected_reboot_str)
+ expect(rebooter).to receive(method_sym).once.and_call_original
+ rebooter.send(method_sym, run_context.node)
+ end
+ end
+
+ describe 'when using #reboot_if_needed!' do
+ include_context 'test a reboot method'
+
+ it 'should produce the correct string on Windows' do
+ test_rebooter_method(:reboot_if_needed!, true, expected[:windows])
+ end
+
+ it 'should produce the correct (Linux-specific) string on non-Windows' do
+ test_rebooter_method(:reboot_if_needed!, false, expected[:linux])
+ end
+ end
+
+ describe 'when using #reboot!' do
+ include_context 'test a reboot method'
+
+ it 'should produce the correct string on Windows' do
+ test_rebooter_method(:reboot!, true, expected[:windows])
+ end
+
+ it 'should produce the correct (Linux-specific) string on non-Windows' do
+ test_rebooter_method(:reboot!, false, expected[:linux])
+ end
+ end
+ end
+ end
+end
diff --git a/spec/functional/resource/deploy_revision_spec.rb b/spec/functional/resource/deploy_revision_spec.rb
index 9ff1391e35..eae422ac1d 100644
--- a/spec/functional/resource/deploy_revision_spec.rb
+++ b/spec/functional/resource/deploy_revision_spec.rb
@@ -59,7 +59,6 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
let(:event_dispatch) { Chef::EventDispatch::Dispatcher.new }
let(:run_context) { Chef::RunContext.new(node, {}, event_dispatch) }
-
# These tests use git's bundle feature, which is a way to export an entire
# git repo (or subset of commits) as a single file.
#
@@ -799,7 +798,6 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
deploy_to_latest_with_callback_tracking.run_action(:deploy)
end
-
let(:deploy_that_fails) do
resource = deploy_to_latest_rev.dup
errant_callback = lambda {|x| raise Exception, "I am a failed deploy" }
@@ -882,5 +880,3 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
end
end
-
-
diff --git a/spec/functional/resource/file_spec.rb b/spec/functional/resource/file_spec.rb
index d6f56db3e9..99966f85c8 100644
--- a/spec/functional/resource/file_spec.rb
+++ b/spec/functional/resource/file_spec.rb
@@ -24,12 +24,18 @@ describe Chef::Resource::File do
let(:file_base) { "file_spec" }
let(:expected_content) { "Don't fear the ruby." }
- def create_resource
+ def create_resource(opts={})
events = Chef::EventDispatch::Dispatcher.new
node = Chef::Node.new
run_context = Chef::RunContext.new(node, {}, events)
- resource = Chef::Resource::File.new(path, run_context)
- resource
+
+ use_path = if opts[:use_relative_path]
+ File.basename(path)
+ else
+ path
+ end
+
+ Chef::Resource::File.new(use_path, run_context)
end
let(:resource) do
@@ -42,6 +48,10 @@ describe Chef::Resource::File do
create_resource
end
+ let(:resource_with_relative_path) do
+ create_resource(:use_relative_path => true)
+ end
+
let(:unmanaged_content) do
"This is file content that is not managed by chef"
end
@@ -74,6 +84,19 @@ describe Chef::Resource::File do
end
end
+ # github issue 1842.
+ describe "when running action :create on a relative path" do
+ before do
+ resource_with_relative_path.run_action(:create)
+ end
+
+ context "and the file exists" do
+ it "should run without an exception" do
+ resource_with_relative_path.run_action(:create)
+ end
+ end
+ end
+
describe "when running action :touch" do
context "and the target file does not exist" do
before do
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb
index 8e630d84f2..2220e973cf 100644
--- a/spec/functional/resource/link_spec.rb
+++ b/spec/functional/resource/link_spec.rb
@@ -72,8 +72,8 @@ describe Chef::Resource::Link do
end
end
- def canonicalize(path)
- windows? ? path.gsub('/', '\\') : path
+ def paths_eql?(path1, path2)
+ Chef::Util::PathHelper.paths_eql?(path1, path2)
end
def symlink(a, b)
@@ -180,7 +180,7 @@ describe Chef::Resource::Link do
it 'links to the target file' do
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(to)
+ paths_eql?(readlink(target_file), to).should be_true
end
it 'marks the resource updated' do
resource.should be_updated
@@ -201,7 +201,7 @@ describe Chef::Resource::Link do
it 'leaves the file linked' do
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(to)
+ paths_eql?(readlink(target_file), to).should be_true
end
it 'does not mark the resource updated' do
resource.should_not be_updated
@@ -279,7 +279,7 @@ describe Chef::Resource::Link do
before(:each) do
symlink(to, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(to)
+ paths_eql?(readlink(target_file), to).should be_true
end
include_context 'create symbolic link is noop'
include_context 'delete succeeds'
@@ -294,7 +294,7 @@ describe Chef::Resource::Link do
File.open(@other_target, 'w') { |file| file.write('eek') }
symlink(@other_target, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(@other_target)
+ paths_eql?(readlink(target_file), @other_target).should be_true
end
after(:each) do
File.delete(@other_target)
@@ -311,7 +311,7 @@ describe Chef::Resource::Link do
nonexistent = File.join(test_file_dir, make_tmpname('nonexistent_spec'))
symlink(nonexistent, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(nonexistent)
+ paths_eql?(readlink(target_file), nonexistent).should be_true
end
include_context 'create symbolic link succeeds'
include_context 'delete succeeds'
@@ -393,7 +393,7 @@ describe Chef::Resource::Link do
File.open(@other_target, "w") { |file| file.write("eek") }
symlink(@other_target, to)
symlink?(to).should be_true
- readlink(to).should == canonicalize(@other_target)
+ paths_eql?(readlink(to), @other_target).should be_true
end
after(:each) do
File.delete(@other_target)
@@ -408,7 +408,7 @@ describe Chef::Resource::Link do
@other_target = File.join(test_file_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
- readlink(to).should == canonicalize(@other_target)
+ paths_eql?(readlink(to), @other_target).should be_true
end
context 'and the link does not yet exist' do
include_context 'create symbolic link succeeds'
@@ -441,7 +441,7 @@ describe Chef::Resource::Link do
before(:each) do
symlink(to, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(to)
+ paths_eql?(readlink(target_file), to).should be_true
end
include_context 'create symbolic link is noop'
include_context 'delete succeeds'
@@ -450,7 +450,7 @@ describe Chef::Resource::Link do
before(:each) do
symlink(absolute_to, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(absolute_to)
+ paths_eql?(readlink(target_file), absolute_to).should be_true
end
include_context 'create symbolic link succeeds'
include_context 'delete succeeds'
@@ -478,7 +478,7 @@ describe Chef::Resource::Link do
before(:each) do
symlink(to, target_file)
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(to)
+ paths_eql?(readlink(target_file), to).should be_true
end
include_context 'create hard link succeeds'
it_behaves_like 'delete errors out'
@@ -552,7 +552,7 @@ describe Chef::Resource::Link do
File.open(@other_target, "w") { |file| file.write("eek") }
symlink(@other_target, to)
symlink?(to).should be_true
- readlink(to).should == canonicalize(@other_target)
+ paths_eql?(readlink(to), @other_target).should be_true
end
after(:each) do
File.delete(@other_target)
@@ -564,7 +564,7 @@ describe Chef::Resource::Link do
# OS X gets angry about this sort of link. Bug in OS X, IMO.
pending('OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks', :if => (os_x? or freebsd? or aix?)) do
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(@other_target)
+ paths_eql?(readlink(target_file), @other_target).should be_true
end
end
include_context 'delete is noop'
@@ -575,7 +575,7 @@ describe Chef::Resource::Link do
@other_target = File.join(test_file_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
- readlink(to).should == canonicalize(@other_target)
+ paths_eql?(readlink(to), @other_target).should be_true
end
context 'and the link does not yet exist' do
it 'links to the target file' do
@@ -588,7 +588,7 @@ describe Chef::Resource::Link do
File.exists?(target_file).should be_false
end
symlink?(target_file).should be_true
- readlink(target_file).should == canonicalize(@other_target)
+ paths_eql?(readlink(target_file), @other_target).should be_true
end
end
include_context 'delete is noop'
diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb
new file mode 100644
index 0000000000..735ca994c8
--- /dev/null
+++ b/spec/functional/resource/reboot_spec.rb
@@ -0,0 +1,103 @@
+#
+# Author:: Chris Doherty <cdoherty@getchef.com>)
+# Copyright:: Copyright (c) 2014 Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Resource::Reboot do
+
+ let(:expected) do
+ {
+ :delay_mins => 5,
+ :requested_by => "reboot resource functional test",
+ :reason => "reboot resource spec test"
+ }
+ end
+
+ def create_resource
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ resource = Chef::Resource::Reboot.new(expected[:requested_by], run_context)
+ resource.delay_mins(expected[:delay_mins])
+ resource.reason(expected[:reason])
+ resource
+ end
+
+ let(:resource) do
+ create_resource
+ end
+
+ shared_context 'testing run context modification' do
+ def test_reboot_action(resource)
+ reboot_info = resource.run_context.reboot_info
+ expect(reboot_info.keys.sort).to eq([:delay_mins, :reason, :requested_by, :timestamp])
+ expect(reboot_info[:delay_mins]).to eq(expected[:delay_mins])
+ expect(reboot_info[:reason]).to eq(expected[:reason])
+ expect(reboot_info[:requested_by]).to eq(expected[:requested_by])
+
+ expect(resource.run_context.reboot_requested?).to be_true
+ end
+ end
+
+ # the currently defined behavior for multiple calls to this resource is "last one wins."
+ describe 'the request_reboot_on_successful_run action' do
+ include_context 'testing run context modification'
+
+ before do
+ resource.run_action(:request_reboot)
+ end
+
+ after do
+ resource.run_context.cancel_reboot
+ end
+
+ it 'should have modified the run context correctly' do
+ test_reboot_action(resource)
+ end
+ end
+
+ describe 'the reboot_interrupt_run action' do
+ include_context 'testing run context modification'
+
+ after do
+ resource.run_context.cancel_reboot
+ end
+
+ it 'should have modified the run context correctly' do
+ # this doesn't actually test the flow of Chef::Client#do_run, unfortunately.
+ expect {
+ resource.run_action(:reboot_now)
+ }.to throw_symbol(:end_client_run_early)
+
+ test_reboot_action(resource)
+ end
+ end
+
+ describe "the cancel action" do
+ before do
+ resource.run_context.request_reboot(expected)
+ resource.run_action(:cancel)
+ end
+
+ it 'should have cleared the reboot request' do
+ # arguably we shouldn't be querying RunContext's internal data directly.
+ expect(resource.run_context.reboot_info).to eq({})
+ expect(resource.run_context.reboot_requested?).to be_false
+ end
+ end
+end
diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply.rb
index 32c98c6ed6..62a53c2a31 100644
--- a/spec/unit/application/apply.rb
+++ b/spec/unit/application/apply.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
describe Chef::Application::Apply do
before do
- @app = Chef::Application::Recipe.new
+ @app = Chef::Application::Apply.new
@app.stub(:configure_logging).and_return(true)
@recipe_text = "package 'nyancat'"
Chef::Config[:solo] = true
@@ -73,4 +73,14 @@ describe Chef::Application::Apply do
@recipe_fh.path.should == @app.instance_variable_get(:@recipe_filename)
end
end
+ describe "recipe_file_arg" do
+ before do
+ ARGV.clear
+ end
+ it "should exit and log message" do
+ Chef::Log.should_receive(:debug).with(/^No recipe file provided/)
+ lambda { @app.run }.should raise_error(SystemExit) { |e| e.status.should == 1 }
+ end
+
+ end
end
diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb
index 8576ae168a..0d643514e0 100644
--- a/spec/unit/dsl/reboot_pending_spec.rb
+++ b/spec/unit/dsl/reboot_pending_spec.rb
@@ -21,7 +21,7 @@ require "spec_helper"
describe Chef::DSL::RebootPending do
describe "reboot_pending?" do
- describe "in isoloation" do
+ describe "in isolation" do
let(:recipe) { Object.new.extend(Chef::DSL::RebootPending) }
before do
@@ -74,12 +74,6 @@ describe Chef::DSL::RebootPending do
end
end
- context "platform is not supported" do
- it 'should raise an exception' do
- recipe.stub_chain(:node, :[]).with(:platform).and_return('msdos')
- expect { recipe.reboot_pending? }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
- end
- end
end # describe in isolation
describe "in a recipe" do
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 064f8c5621..6427071a6b 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -119,7 +119,20 @@ EXPECTED
context "via config[:secret_file]" do
let(:chef_config) do
{
- :knife => {:secret_file => secret_file}
+ :knife => {:secret_file => secret_file}
+ }
+ end
+ it "reads the encrypted_data_bag_secret" do
+ bootstrap_context.encrypted_data_bag_secret.should eq IO.read(secret_file)
+ end
+ end
+
+ context "via config[:secret_file] with short home path" do
+ let(:chef_config) do
+ home_path = File.expand_path("~")
+ shorted_secret_file_path = secret_file.gsub(home_path, "~")
+ {
+ :knife => {:secret_file => shorted_secret_file_path}
}
end
it "reads the encrypted_data_bag_secret" do
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 1f85ec6bf1..38a63a32ee 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -32,7 +32,7 @@ describe Chef::Mixin::ShellOut do
let(:output) { StringIO.new }
let!(:capture_log_output) { Chef::Log.logger = Logger.new(output) }
- let(:assume_deprecation_log_level) { Chef::Log.stub(:level).and_return(:warn) }
+ let(:assume_deprecation_log_level) { allow(Chef::Log).to receive(:level).and_return(:warn) }
context 'without options' do
let(:command_args) { [ cmd ] }
@@ -55,9 +55,9 @@ describe Chef::Mixin::ShellOut do
it 'should emit a deprecation warning' do
assume_deprecation_log_level and capture_log_output
subject
- output.string.should match /DEPRECATION:/
- output.string.should match Regexp.escape(old_option.to_s)
- output.string.should match Regexp.escape(new_option.to_s)
+ expect(output.string).to match /DEPRECATION:/
+ expect(output.string).to match Regexp.escape(old_option.to_s)
+ expect(output.string).to match Regexp.escape(new_option.to_s)
end
end
@@ -106,7 +106,7 @@ describe Chef::Mixin::ShellOut do
end
end
- describe "#shell_out_with_systems_locale" do
+ context "when testing individual methods" do
before(:each) do
@original_env = ENV.to_hash
ENV.clear
@@ -120,82 +120,152 @@ describe Chef::Mixin::ShellOut do
let(:shell_out) { Chef::Mixin::ShellOut }
let(:cmd) { "echo '#{rand(1000)}'" }
- describe "when the last argument is a Hash" do
- describe "and environment is an option" do
- it "should not change environment['LC_ALL'] when set to nil" do
- options = { :environment => { 'LC_ALL' => nil } }
- shell_out.should_receive(:shell_out).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "#shell_out" do
+
+ describe "when the last argument is a Hash" do
+ describe "and environment is an option" do
+ it "should not change environment['LC_ALL'] when set to nil" do
+ options = { :environment => { 'LC_ALL' => nil } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should not change environment['LC_ALL'] when set to non-nil" do
+ options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should set environment['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
+ options = { :environment => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should not mutate the options hash when it adds LC_ALL" do
+ options = { :environment => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd, options)
+ expect(options[:environment].has_key?('LC_ALL')).to be false
+ end
end
- it "should not change environment['LC_ALL'] when set to non-nil" do
- options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
- shell_out.should_receive(:shell_out).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "and env is an option" do
+ it "should not change env when set to nil" do
+ options = { :env => { 'LC_ALL' => nil } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should not change env when set to non-nil" do
+ options = { :env => { 'LC_ALL' => 'de_DE.UTF-8'}}
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should set env['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
+ options = { :env => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
+
+ it "should not mutate the options hash when it adds LC_ALL" do
+ options = { :env => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd, options)
+ expect(options[:env].has_key?('LC_ALL')).to be false
+ end
end
- it "should set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
- options = { :environment => { 'HOME' => '/Users/morty' } }
- shell_out.should_receive(:shell_out).with(
- cmd,
- { :environment => {
- 'HOME' => '/Users/morty',
- 'LC_ALL' => nil }
- }
- ).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "and no env/environment option is present" do
+ it "should add environment option and set environment['LC_ALL'] to 'en_US.UTF_8'" do
+ options = { :user => 'morty' }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :user => 'morty', :environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd, options)
+ end
end
end
- describe "and env is an option" do
- it "should not change env when set to nil" do
- options = { :env => { 'LC_ALL' => nil } }
- shell_out.should_receive(:shell_out).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "when the last argument is not a Hash" do
+ it "should add environment options and set environment['LC_ALL'] to 'en_US.UTF-8'" do
+ expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ :environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
+ }).and_return(true)
+ shell_out.shell_out(cmd)
end
+ end
+
+ end
- it "should not change env when set to non-nil" do
- options = { :env => { 'LC_ALL' => 'en_US.UTF-8'}}
- shell_out.should_receive(:shell_out).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "#shell_out_with_systems_locale" do
+
+ describe "when the last argument is a Hash" do
+ describe "and environment is an option" do
+ it "should not change environment['LC_ALL'] when set to nil" do
+ options = { :environment => { 'LC_ALL' => nil } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+
+ it "should not change environment['LC_ALL'] when set to non-nil" do
+ options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+
+ it "should no longer set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
+ options = { :environment => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
end
- it "should set env['LC_ALL'] to nil when 'LC_ALL' not present" do
- options = { :env => { 'HOME' => '/Users/morty' } }
- shell_out.should_receive(:shell_out).with(
- cmd,
- { :env => {
- 'HOME' => '/Users/morty',
- 'LC_ALL' => nil }
- }
- ).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "and env is an option" do
+ it "should not change env when set to nil" do
+ options = { :env => { 'LC_ALL' => nil } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+
+ it "should not change env when set to non-nil" do
+ options = { :env => { 'LC_ALL' => 'en_US.UTF-8'}}
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+
+ it "should no longer set env['LC_ALL'] to nil when 'LC_ALL' not present" do
+ options = { :env => { 'HOME' => '/Users/morty' } }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
end
- end
- describe "and no env/environment option is present" do
- it "should add environment option and set environment['LC_ALL'] to nil" do
- options = { :user => 'morty' }
- shell_out.should_receive(:shell_out).with(
- cmd,
- { :environment => { 'LC_ALL' => nil },
- :user => 'morty'
- }
- ).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ describe "and no env/environment option is present" do
+ it "should no longer add environment option and set environment['LC_ALL'] to nil" do
+ options = { :user => 'morty' }
+ expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
end
end
- end
- describe "when the last argument is not a Hash" do
- it "should add environment options and set environment['LC_ALL'] to nil" do
- shell_out.should_receive(:shell_out).with(
- cmd,
- { :environment => { 'LC_ALL' => nil } }
- ).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd)
+ describe "when the last argument is not a Hash" do
+ it "should no longer add environment options and set environment['LC_ALL'] to nil" do
+ expect(shell_out).to receive(:shell_out_command).with(cmd).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd)
+ end
end
end
- end
+ end
end
diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb
index c6a37fdd5b..f4fd1480e0 100644
--- a/spec/unit/provider/ifconfig/debian_spec.rb
+++ b/spec/unit/provider/ifconfig/debian_spec.rb
@@ -56,8 +56,6 @@ describe Chef::Provider::Ifconfig::Debian do
describe "generate_config" do
context "when writing a file" do
- let(:config_file_ifcfg) { StringIO.new }
-
let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") }
let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") }
@@ -67,14 +65,13 @@ describe Chef::Provider::Ifconfig::Debian do
before do
stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_FILE", tempfile.path)
stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_DOT_D_DIR", tempdir_path)
- expect(File).to receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
end
it "should write a network-script" do
provider.run_action(:add)
- expect(config_file_ifcfg.string).to match(/^iface eth0 inet static\s*$/)
- expect(config_file_ifcfg.string).to match(/^\s+address 10\.0\.0\.1\s*$/)
- expect(config_file_ifcfg.string).to match(/^\s+netmask 255\.255\.254\.0\s*$/)
+ expect(File.read(config_filename_ifcfg)).to match(/^iface eth0 inet static\s*$/)
+ expect(File.read(config_filename_ifcfg)).to match(/^\s+address 10\.0\.0\.1\s*$/)
+ expect(File.read(config_filename_ifcfg)).to match(/^\s+netmask 255\.255\.254\.0\s*$/)
end
context "when the interface_dot_d directory does not exist" do
@@ -123,7 +120,6 @@ iface eth0 inet static
netmask 255.255.254.0
EOF
)
- expect(File).to receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
expect(File.exists?(tempdir_path)).to be_true # since the file exists, the enclosing dir must also exist
end
@@ -139,6 +135,8 @@ EOF
before do
tempfile.write(expected_string)
tempfile.close
+
+ expect(provider).not_to receive(:converge_by).with(/modifying #{tempfile.path} to source #{tempdir_path}/)
end
it "should preserve all the contents" do
@@ -165,6 +163,9 @@ EOF
before do
tempfile.write("a line\nanother line\n")
tempfile.close
+
+ allow(provider).to receive(:converge_by).and_call_original
+ expect(provider).to receive(:converge_by).with(/modifying #{tempfile.path} to source #{tempdir_path}/).and_call_original
end
it "should preserve the original contents and add the source line" do
@@ -318,8 +319,17 @@ source #{tempdir_path}/*
it "should delete network-script if it exists" do
current_resource.device new_resource.device
- expect(File).to receive(:exist?).with(config_filename_ifcfg).and_return(true)
- expect(FileUtils).to receive(:rm_f).with(config_filename_ifcfg, :verbose => false)
+
+ [:exist?, :exists?, :writable?].each do |cmd|
+ # need to stub :writable? to make why_run? happy
+ allow(File).to receive(cmd).and_call_original
+ allow(File).to receive(cmd).with(config_filename_ifcfg).and_return(true)
+ end
+
+ # stub for Chef::Util::Backup#do_backup
+ expect(FileUtils).to receive(:cp)
+ .with(config_filename_ifcfg, /#{Chef::Config[:file_backup_path]}/, :preserve => true)
+ expect(File).to receive(:delete).with(config_filename_ifcfg)
provider.run_action(:delete)
end
diff --git a/spec/unit/provider/ifconfig/redhat_spec.rb b/spec/unit/provider/ifconfig/redhat_spec.rb
index f4b98dfc32..138c2a389d 100644
--- a/spec/unit/provider/ifconfig/redhat_spec.rb
+++ b/spec/unit/provider/ifconfig/redhat_spec.rb
@@ -37,22 +37,26 @@ describe Chef::Provider::Ifconfig::Redhat do
status = double("Status", :exitstatus => 0)
@provider.instance_variable_set("@status", status)
@provider.current_resource = @current_resource
- end
+
+ config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}"
+ @config = double("chef-resource-file")
+ @provider.should_receive(:resource_for_config).with(config_filename).and_return(@config)
+ end
describe "generate_config for action_add" do
- it "should write network-script for centos" do
+ it "should write network-script for centos" do
@provider.stub(:load_current_resource)
@provider.stub(:run_command)
- config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}"
- config_file = StringIO.new
- File.should_receive(:new).with(config_filename, "w").and_return(config_file)
-
+ @config.should_receive(:content) do |arg|
+ arg.should match(/^\s*DEVICE=eth0\s*$/)
+ arg.should match(/^\s*IPADDR=10\.0\.0\.1\s*$/)
+ arg.should match(/^\s*NETMASK=255\.255\.254\.0\s*$/)
+ end
+ @config.should_receive(:run_action).with(:create)
+ @config.should_receive(:updated?).and_return(true)
@provider.run_action(:add)
- config_file.string.should match(/^\s*DEVICE=eth0\s*$/)
- config_file.string.should match(/^\s*IPADDR=10\.0\.0\.1\s*$/)
- config_file.string.should match(/^\s*NETMASK=255\.255\.254\.0\s*$/)
- end
+ end
end
describe "delete_config for action_delete" do
@@ -61,10 +65,8 @@ describe Chef::Provider::Ifconfig::Redhat do
@current_resource.device @new_resource.device
@provider.stub(:load_current_resource)
@provider.stub(:run_command)
- config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}"
- File.should_receive(:exist?).with(config_filename).and_return(true)
- FileUtils.should_receive(:rm_f).with(config_filename, :verbose => false)
-
+ @config.should_receive(:run_action).with(:delete)
+ @config.should_receive(:updated?).and_return(true)
@provider.run_action(:delete)
end
end
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index fb8d0956d7..b09e365c65 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -72,7 +72,7 @@ describe Chef::Provider::Ifconfig do
@provider.stub(:load_current_resource)
@provider.should_not_receive(:run_command)
@current_resource.inet_addr "10.0.0.1"
- @provider.should_not_receive(:generate_config)
+ @provider.should_receive(:generate_config)
@provider.run_action(:add)
@new_resource.should_not be_updated
@@ -123,7 +123,7 @@ describe Chef::Provider::Ifconfig do
it "should not delete interface if it does not exist" do
@provider.stub(:load_current_resource)
@provider.should_not_receive(:run_command)
- @provider.should_not_receive(:delete_config)
+ @provider.should_receive(:delete_config)
@provider.run_action(:delete)
@new_resource.should_not be_updated
@@ -171,7 +171,7 @@ describe Chef::Provider::Ifconfig do
@provider.stub(:load_current_resource)
# This is so that nothing actually runs
@provider.should_not_receive(:run_command)
- @provider.should_not_receive(:delete_config)
+ @provider.should_receive(:delete_config)
@provider.run_action(:delete)
@new_resource.should_not be_updated
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index 6052f5dd3b..2f0a5f2020 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -38,8 +38,8 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
result
end
- def canonicalize(path)
- Chef::Platform.windows? ? path.gsub('/', '\\') : path
+ def paths_eql?(path1, path2)
+ Chef::Util::PathHelper.paths_eql?(path1, path2)
end
describe "when the target is a symlink" do
@@ -68,7 +68,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
provider.current_resource.link_type.should == :symbolic
end
it "should update the source of the existing link with the links target" do
- provider.current_resource.to.should == canonicalize("#{CHEF_SPEC_DATA}/fofile")
+ paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true
end
it "should set the owner" do
provider.current_resource.owner.should == 501
@@ -110,7 +110,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
provider.current_resource.link_type.should == :symbolic
end
it "should update the source of the existing link to the link's target" do
- provider.current_resource.to.should == canonicalize("#{CHEF_SPEC_DATA}/fofile")
+ paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true
end
it "should not set the owner" do
provider.current_resource.owner.should be_nil
@@ -221,7 +221,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
provider.current_resource.link_type.should == :hard
end
it "should update the source of the existing link to the link's target" do
- provider.current_resource.to.should == canonicalize("#{CHEF_SPEC_DATA}/fofile")
+ paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true
end
it "should not set the owner" do
provider.current_resource.owner.should == nil
diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb
index 35f85b628f..5d6e23302f 100644
--- a/spec/unit/provider/package/aix_spec.rb
+++ b/spec/unit/provider/package/aix_spec.rb
@@ -59,7 +59,6 @@ describe Chef::Provider::Package::Aix do
lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package)
end
-
it "should get the source package version from lslpp if provided" do
@stdout = StringIO.new(@bffinfo)
@stdin, @stderr = StringIO.new, StringIO.new
@@ -125,9 +124,7 @@ describe Chef::Provider::Package::Aix do
describe "install and upgrade" do
it "should run installp -aYF -d with the package source to install" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "installp -aYF -d /tmp/samba.base samba.base"
- })
+ @provider.should_receive(:shell_out!).with("installp -aYF -d /tmp/samba.base samba.base")
@provider.install_package("samba.base", "3.3.12.0")
end
@@ -135,37 +132,28 @@ describe Chef::Provider::Package::Aix do
@new_resource = Chef::Resource::Package.new("/tmp/samba.base")
@provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context)
@new_resource.source.should == "/tmp/samba.base"
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "installp -aYF -d /tmp/samba.base /tmp/samba.base"
- })
+ @provider.should_receive(:shell_out!).with("installp -aYF -d /tmp/samba.base /tmp/samba.base")
@provider.install_package("/tmp/samba.base", "3.3.12.0")
end
it "should run installp with -eLogfile option." do
@new_resource.stub(:options).and_return("-e/tmp/installp.log")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base"
- })
+ @provider.should_receive(:shell_out!).with("installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base")
@provider.install_package("samba.base", "3.3.12.0")
end
end
describe "remove" do
it "should run installp -u samba.base to remove the package" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "installp -u samba.base"
- })
+ @provider.should_receive(:shell_out!).with("installp -u samba.base")
@provider.remove_package("samba.base", "3.3.12.0")
end
it "should run installp -u -e/tmp/installp.log with options -e/tmp/installp.log" do
@new_resource.stub(:options).and_return("-e/tmp/installp.log")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "installp -u -e/tmp/installp.log samba.base"
- })
+ @provider.should_receive(:shell_out!).with("installp -u -e/tmp/installp.log samba.base")
@provider.remove_package("samba.base", "3.3.12.0")
end
end
end
-
diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb
index c5941c2a91..07bca7f6d5 100644
--- a/spec/unit/provider/package/ips_spec.rb
+++ b/spec/unit/provider/package/ips_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Provider::Package::Ips do
pkg: info: no packages matching the following patterns you specified are
installed on the system. Try specifying -r to query remotely:
- crypto/gnupg
+ crypto/gnupg
PKG_STATUS
return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 1)
end
@@ -59,7 +59,7 @@ Packaging Date: April 1, 2012 05:55:52 PM
FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
PKG_STATUS
stdin = StringIO.new
- stderr = ''
+ stderr = ''
return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 0)
end
@@ -123,17 +123,12 @@ INSTALLED
context "when installing a package" do
it "should run pkg install with the package name and version" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg install -q crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17")
@provider.install_package("crypto/gnupg", "2.0.17")
end
-
it "should run pkg install with the package name and version and options if specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg --no-refresh install -q crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out).with("pkg --no-refresh install -q crypto/gnupg@2.0.17")
@new_resource.stub(:options).and_return("--no-refresh")
@provider.install_package("crypto/gnupg", "2.0.17")
end
@@ -206,9 +201,7 @@ REMOTE
end
it "should run pkg install with the --accept flag" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg install -q --accept crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out).with("pkg install -q --accept crypto/gnupg@2.0.17")
@provider.install_package("crypto/gnupg", "2.0.17")
end
end
@@ -216,25 +209,19 @@ REMOTE
context "when upgrading a package" do
it "should run pkg install with the package name and version" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg install -q crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17")
@provider.upgrade_package("crypto/gnupg", "2.0.17")
end
end
context "when uninstalling a package" do
it "should run pkg uninstall with the package name and version" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg uninstall -q crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out!).with("pkg uninstall -q crypto/gnupg@2.0.17")
@provider.remove_package("crypto/gnupg", "2.0.17")
end
it "should run pkg uninstall with the package name and version and options if specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg --no-refresh uninstall -q crypto/gnupg@2.0.17"
- })
+ @provider.should_receive(:shell_out!).with("pkg --no-refresh uninstall -q crypto/gnupg@2.0.17")
@new_resource.stub(:options).and_return("--no-refresh")
@provider.remove_package("crypto/gnupg", "2.0.17")
end
diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb
index 9ebf23860d..535a5d2459 100644
--- a/spec/unit/provider/package/macports_spec.rb
+++ b/spec/unit/provider/package/macports_spec.rb
@@ -105,7 +105,7 @@ EOF
it "should run the port install command with the correct version" do
@current_resource.should_receive(:version).and_return("4.1.6")
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port install zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port install zsh @4.2.7")
@provider.install_package("zsh", "4.2.7")
end
@@ -113,7 +113,7 @@ EOF
it "should not do anything if a package already exists with the same version" do
@current_resource.should_receive(:version).and_return("4.2.7")
@provider.current_resource = @current_resource
- @provider.should_not_receive(:run_command_with_systems_locale)
+ @provider.should_not_receive(:shell_out!)
@provider.install_package("zsh", "4.2.7")
end
@@ -122,7 +122,7 @@ EOF
@current_resource.should_receive(:version).and_return("4.1.6")
@provider.current_resource = @current_resource
@new_resource.stub(:options).and_return("-f")
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f install zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port -f install zsh @4.2.7")
@provider.install_package("zsh", "4.2.7")
end
@@ -130,36 +130,36 @@ EOF
describe "purge_package" do
it "should run the port uninstall command with the correct version" do
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port uninstall zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port uninstall zsh @4.2.7")
@provider.purge_package("zsh", "4.2.7")
end
it "should purge the currently active version if no explicit version is passed in" do
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port uninstall zsh")
+ @provider.should_receive(:shell_out!).with("port uninstall zsh")
@provider.purge_package("zsh", nil)
end
it "should add options to the port command when specified" do
@new_resource.stub(:options).and_return("-f")
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f uninstall zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port -f uninstall zsh @4.2.7")
@provider.purge_package("zsh", "4.2.7")
end
end
describe "remove_package" do
it "should run the port deactivate command with the correct version" do
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port deactivate zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port deactivate zsh @4.2.7")
@provider.remove_package("zsh", "4.2.7")
end
it "should remove the currently active version if no explicit version is passed in" do
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port deactivate zsh")
+ @provider.should_receive(:shell_out!).with("port deactivate zsh")
@provider.remove_package("zsh", nil)
end
it "should add options to the port command when specified" do
@new_resource.stub(:options).and_return("-f")
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f deactivate zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port -f deactivate zsh @4.2.7")
@provider.remove_package("zsh", "4.2.7")
end
end
@@ -169,7 +169,7 @@ EOF
@current_resource.should_receive(:version).at_least(:once).and_return("4.1.6")
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port upgrade zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port upgrade zsh @4.2.7")
@provider.upgrade_package("zsh", "4.2.7")
end
@@ -177,7 +177,7 @@ EOF
it "should not run the port upgrade command if the version is already installed" do
@current_resource.should_receive(:version).at_least(:once).and_return("4.2.7")
@provider.current_resource = @current_resource
- @provider.should_not_receive(:run_command_with_systems_locale)
+ @provider.should_not_receive(:shell_out!)
@provider.upgrade_package("zsh", "4.2.7")
end
@@ -195,7 +195,7 @@ EOF
@current_resource.should_receive(:version).at_least(:once).and_return("4.1.6")
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f upgrade zsh @4.2.7")
+ @provider.should_receive(:shell_out!).with("port -f upgrade zsh @4.2.7")
@provider.upgrade_package("zsh", "4.2.7")
end
diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb
index 528f7097e8..0c1c487980 100644
--- a/spec/unit/provider/package/pacman_spec.rb
+++ b/spec/unit/provider/package/pacman_spec.rb
@@ -155,16 +155,12 @@ PACMAN_CONF
describe Chef::Provider::Package::Pacman, "install_package" do
it "should run pacman install with the package name and version" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pacman --sync --noconfirm --noprogressbar nano"
- })
+ @provider.should_receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar nano")
@provider.install_package("nano", "1.0")
end
it "should run pacman install with the package name and version and options if specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pacman --sync --noconfirm --noprogressbar --debug nano"
- })
+ @provider.should_receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar --debug nano")
@new_resource.stub(:options).and_return("--debug")
@provider.install_package("nano", "1.0")
@@ -180,16 +176,12 @@ PACMAN_CONF
describe Chef::Provider::Package::Pacman, "remove_package" do
it "should run pacman remove with the package name" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pacman --remove --noconfirm --noprogressbar nano"
- })
+ @provider.should_receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar nano")
@provider.remove_package("nano", "1.0")
end
it "should run pacman remove with the package name and options if specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pacman --remove --noconfirm --noprogressbar --debug nano"
- })
+ @provider.should_receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar --debug nano")
@new_resource.stub(:options).and_return("--debug")
@provider.remove_package("nano", "1.0")
diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb
index 6f22952da2..570f123168 100644
--- a/spec/unit/provider/package/portage_spec.rb
+++ b/spec/unit/provider/package/portage_spec.rb
@@ -278,23 +278,17 @@ EOF
describe Chef::Provider::Package::Portage, "install_package" do
it "should install a normally versioned package using portage" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "emerge -g --color n --nospinner --quiet =dev-util/git-1.0.0"
- })
+ @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet =dev-util/git-1.0.0")
@provider.install_package("dev-util/git", "1.0.0")
end
it "should install a tilde versioned package using portage" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "emerge -g --color n --nospinner --quiet ~dev-util/git-1.0.0"
- })
+ @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet ~dev-util/git-1.0.0")
@provider.install_package("dev-util/git", "~1.0.0")
end
it "should add options to the emerge command when specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0"
- })
+ @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0")
@new_resource.stub(:options).and_return("--oneshot")
@provider.install_package("dev-util/git", "1.0.0")
@@ -303,16 +297,12 @@ EOF
describe Chef::Provider::Package::Portage, "remove_package" do
it "should un-emerge the package with no version specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "emerge --unmerge --color n --nospinner --quiet dev-util/git"
- })
+ @provider.should_receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet dev-util/git")
@provider.remove_package("dev-util/git", nil)
end
it "should un-emerge the package with a version specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "emerge --unmerge --color n --nospinner --quiet =dev-util/git-1.0.0"
- })
+ @provider.should_receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet =dev-util/git-1.0.0")
@provider.remove_package("dev-util/git", "1.0.0")
end
end
diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb
index 6e46cf5e98..9a96d829b8 100644
--- a/spec/unit/provider/package/rpm_spec.rb
+++ b/spec/unit/provider/package/rpm_spec.rb
@@ -102,25 +102,19 @@ describe Chef::Provider::Package::Rpm do
describe "when installing or upgrading" do
it "should run rpm -i with the package source to install" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.install_package("ImageMagick-c++", "6.5.4.7-7.el6_5")
end
it "should run rpm -U with the package source to upgrade" do
@current_resource.version("21.4-19.el5")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5")
end
it "should install package if missing and set to upgrade" do
@current_resource.version("ImageMagick-c++")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5")
end
@@ -130,9 +124,7 @@ describe Chef::Provider::Package::Rpm do
@new_resource.source.should == "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
@current_resource = Chef::Resource::Package.new("ImageMagick-c++")
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
end
@@ -143,30 +135,23 @@ describe Chef::Provider::Package::Rpm do
@current_resource = Chef::Resource::Package.new("ImageMagick-c++")
@current_resource.version("21.4-19.el5")
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
end
it "installs with custom options specified in the resource" do
@provider.candidate_version = '11'
@new_resource.options("--dbpath /var/lib/rpm")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm --dbpath /var/lib/rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm"
- })
+ @provider.should_receive(:shell_out!).with("rpm --dbpath /var/lib/rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
@provider.install_package(@new_resource.name, @provider.candidate_version)
end
end
describe "when removing the package" do
it "should run rpm -e to remove the package" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "rpm -e ImageMagick-c++-6.5.4.7-7.el6_5"
- })
+ @provider.should_receive(:shell_out!).with("rpm -e ImageMagick-c++-6.5.4.7-7.el6_5")
@provider.remove_package("ImageMagick-c++", "6.5.4.7-7.el6_5")
end
end
end
end
-
diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb
index 086e327cce..d83ccbdf06 100644
--- a/spec/unit/provider/package/solaris_spec.rb
+++ b/spec/unit/provider/package/solaris_spec.rb
@@ -69,7 +69,6 @@ PKGINFO
lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package)
end
-
it "should get the source package version from pkginfo if provided" do
@stdout = StringIO.new(@pkginfo)
@stdin, @stderr = StringIO.new, StringIO.new
@@ -136,9 +135,7 @@ PKGINFO
describe "install and upgrade" do
it "should run pkgadd -n -d with the package source to install" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkgadd -n -d /tmp/bash.pkg all"
- })
+ @provider.should_receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all")
@provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16")
end
@@ -146,34 +143,26 @@ PKGINFO
@new_resource = Chef::Resource::Package.new("/tmp/bash.pkg")
@provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context)
@new_resource.source.should == "/tmp/bash.pkg"
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkgadd -n -d /tmp/bash.pkg all"
- })
+ @provider.should_receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all")
@provider.install_package("/tmp/bash.pkg", "11.10.0,REV=2005.01.08.05.16")
end
it "should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin" do
@new_resource.stub(:options).and_return("-a /tmp/myadmin")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all"
- })
+ @provider.should_receive(:shell_out!).with("pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all")
@provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16")
end
end
describe "remove" do
it "should run pkgrm -n to remove the package" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkgrm -n SUNWbash"
- })
+ @provider.should_receive(:shell_out!).with("pkgrm -n SUNWbash")
@provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16")
end
it "should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin" do
@new_resource.stub(:options).and_return("-a /tmp/myadmin")
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkgrm -n -a /tmp/myadmin SUNWbash"
- })
+ @provider.should_receive(:shell_out!).with("pkgrm -n -a /tmp/myadmin SUNWbash")
@provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16")
end
diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb
index b267915e44..38ed74cdee 100644
--- a/spec/unit/provider/service/arch_service_spec.rb
+++ b/spec/unit/provider/service/arch_service_spec.rb
@@ -20,7 +20,6 @@
require 'spec_helper'
require 'ostruct'
-
# most of this code has been ripped from init_service_spec.rb
# and is only slightly modified to match "arch" needs.
@@ -36,7 +35,6 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
@new_resource.pattern("chef")
@new_resource.supports({:status => false})
-
@provider = Chef::Provider::Service::Arch.new(@new_resource, @run_context)
::File.stub(:exists?).with("/etc/rc.conf").and_return(true)
@@ -51,7 +49,6 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
end
end
-
describe "when the service supports status" do
before do
@new_resource.supports({:status => true})
@@ -82,7 +79,6 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
end
-
describe "when a status command has been specified" do
before do
@new_resource.status_command("/etc/rc.d/chefhasmonkeypants status")
@@ -109,7 +105,6 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
end
-
it "should fail if file /etc/rc.conf does not exist" do
::File.stub(:exists?).with("/etc/rc.conf").and_return(false)
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service)
@@ -211,7 +206,6 @@ RUNNING_PS
end
end
-
describe Chef::Provider::Service::Arch, "start_service" do
# before(:each) do
# @new_resource = double("Chef::Resource::Service",
@@ -228,12 +222,12 @@ RUNNING_PS
it "should call the start command if one is specified" do
@new_resource.stub(:start_command).and_return("/etc/rc.d/chef startyousillysally")
- @provider.should_receive(:shell_out!).with("/etc/rc.d/chef startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef startyousillysally")
@provider.start_service()
end
it "should call '/etc/rc.d/service_name start' if no start command is specified" do
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} start")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} start")
@provider.start_service()
end
end
@@ -254,12 +248,12 @@ RUNNING_PS
it "should call the stop command if one is specified" do
@new_resource.stub(:stop_command).and_return("/etc/rc.d/chef itoldyoutostop")
- @provider.should_receive(:shell_out!).with("/etc/rc.d/chef itoldyoutostop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef itoldyoutostop")
@provider.stop_service()
end
it "should call '/etc/rc.d/service_name stop' if no stop command is specified" do
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} stop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} stop")
@provider.stop_service()
end
end
@@ -281,13 +275,13 @@ RUNNING_PS
it "should call 'restart' on the service_name if the resource supports it" do
@new_resource.stub(:supports).and_return({:restart => true})
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restart")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} restart")
@provider.restart_service()
end
it "should call the restart_command if one has been specified" do
@new_resource.stub(:restart_command).and_return("/etc/rc.d/chef restartinafire")
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire")
@provider.restart_service()
end
@@ -316,13 +310,13 @@ RUNNING_PS
it "should call 'reload' on the service if it supports it" do
@new_resource.stub(:supports).and_return({:reload => true})
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} reload")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} reload")
@provider.reload_service()
end
it "should should run the user specified reload command if one is specified and the service doesn't support reload" do
@new_resource.stub(:reload_command).and_return("/etc/rc.d/chef lollerpants")
- @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants")
@provider.reload_service()
end
end
diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb
index 567eb6744a..3e60857cbf 100644
--- a/spec/unit/provider/service/debian_service_spec.rb
+++ b/spec/unit/provider/service/debian_service_spec.rb
@@ -301,7 +301,7 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
def expect_commands(provider, commands)
commands.each do |command|
- provider.should_receive(:run_command).with({:command => command})
+ provider.should_receive(:shell_out!).with(command)
end
end
diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb
index 6e58e82b97..eb55fac820 100644
--- a/spec/unit/provider/service/freebsd_service_spec.rb
+++ b/spec/unit/provider/service/freebsd_service_spec.rb
@@ -452,12 +452,12 @@ EOF
describe Chef::Provider::Service::Freebsd, "start_service" do
it "should call the start command if one is specified" do
new_resource.start_command("/etc/rc.d/chef startyousillysally")
- expect(provider).to receive(:shell_out!).with("/etc/rc.d/chef startyousillysally")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef startyousillysally")
provider.start_service()
end
it "should call '/usr/local/etc/rc.d/service_name faststart' if no start command is specified" do
- expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststart")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststart")
provider.start_service()
end
end
@@ -465,12 +465,12 @@ EOF
describe Chef::Provider::Service::Freebsd, "stop_service" do
it "should call the stop command if one is specified" do
new_resource.stop_command("/etc/init.d/chef itoldyoutostop")
- expect(provider).to receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef itoldyoutostop")
provider.stop_service()
end
it "should call '/usr/local/etc/rc.d/service_name faststop' if no stop command is specified" do
- expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststop")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststop")
provider.stop_service()
end
end
@@ -478,13 +478,13 @@ EOF
describe Chef::Provider::Service::Freebsd, "restart_service" do
it "should call 'restart' on the service_name if the resource supports it" do
new_resource.supports({:restart => true})
- expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} fastrestart")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} fastrestart")
provider.restart_service()
end
it "should call the restart_command if one has been specified" do
new_resource.restart_command("/etc/init.d/chef restartinafire")
- expect(provider).to receive(:shell_out!).with("/etc/init.d/chef restartinafire")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef restartinafire")
provider.restart_service()
end
diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb
index 95dc04108d..022a73cc9a 100644
--- a/spec/unit/provider/service/gentoo_service_spec.rb
+++ b/spec/unit/provider/service/gentoo_service_spec.rb
@@ -128,14 +128,14 @@ describe Chef::Provider::Service::Gentoo do
describe Chef::Provider::Service::Gentoo, "enable_service" do
it "should call rc-update add *service* default" do
- @provider.should_receive(:run_command).with({:command => "/sbin/rc-update add chef default"})
+ @provider.should_receive(:shell_out!).with("/sbin/rc-update add chef default")
@provider.enable_service()
end
end
describe Chef::Provider::Service::Gentoo, "disable_service" do
it "should call rc-update del *service* default" do
- @provider.should_receive(:run_command).with({:command => "/sbin/rc-update del chef default"})
+ @provider.should_receive(:shell_out!).with("/sbin/rc-update del chef default")
@provider.disable_service()
end
end
diff --git a/spec/unit/provider/service/init_service_spec.rb b/spec/unit/provider/service/init_service_spec.rb
index ad887c84a5..b523f6d3a9 100644
--- a/spec/unit/provider/service/init_service_spec.rb
+++ b/spec/unit/provider/service/init_service_spec.rb
@@ -100,7 +100,7 @@ PS
end
it "should use the init_command if one has been specified" do
- @provider.should_receive(:shell_out!).with("/opt/chef-server/service/erchef start")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/opt/chef-server/service/erchef start")
@provider.start_service
end
@@ -126,7 +126,6 @@ PS
end
-
describe "when we have a 'ps' attribute" do
it "should shell_out! the node's ps command" do
@provider.should_receive(:shell_out!).and_return(@status)
@@ -165,12 +164,12 @@ RUNNING_PS
describe "when starting the service" do
it "should call the start command if one is specified" do
@new_resource.start_command("/etc/init.d/chef startyousillysally")
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally")
@provider.start_service()
end
it "should call '/etc/init.d/service_name start' if no start command is specified" do
- @provider.should_receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} start")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} start")
@provider.start_service()
end
end
@@ -178,12 +177,12 @@ RUNNING_PS
describe Chef::Provider::Service::Init, "stop_service" do
it "should call the stop command if one is specified" do
@new_resource.stop_command("/etc/init.d/chef itoldyoutostop")
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef itoldyoutostop")
@provider.stop_service()
end
it "should call '/etc/init.d/service_name stop' if no stop command is specified" do
- @provider.should_receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} stop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} stop")
@provider.stop_service()
end
end
@@ -191,13 +190,13 @@ RUNNING_PS
describe "when restarting a service" do
it "should call 'restart' on the service_name if the resource supports it" do
@new_resource.supports({:restart => true})
- @provider.should_receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} restart")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restart")
@provider.restart_service()
end
it "should call the restart_command if one has been specified" do
@new_resource.restart_command("/etc/init.d/chef restartinafire")
- @provider.should_receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} restartinafire")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restartinafire")
@provider.restart_service()
end
@@ -212,13 +211,13 @@ RUNNING_PS
describe "when reloading a service" do
it "should call 'reload' on the service if it supports it" do
@new_resource.supports({:reload => true})
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef reload")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef reload")
@provider.reload_service()
end
it "should should run the user specified reload command if one is specified and the service doesn't support reload" do
@new_resource.reload_command("/etc/init.d/chef lollerpants")
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef lollerpants")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef lollerpants")
@provider.reload_service()
end
end
@@ -226,6 +225,7 @@ RUNNING_PS
describe "when a custom command has been specified" do
before do
@new_resource.start_command("/etc/init.d/chef startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally")
end
it "should still pass all why run assertions" do
diff --git a/spec/unit/provider/service/insserv_service_spec.rb b/spec/unit/provider/service/insserv_service_spec.rb
index 04e63458a0..9ed03b519f 100644
--- a/spec/unit/provider/service/insserv_service_spec.rb
+++ b/spec/unit/provider/service/insserv_service_spec.rb
@@ -60,17 +60,16 @@ describe Chef::Provider::Service::Insserv do
describe "enable_service" do
it "should call insserv and create the default links" do
- @provider.should_receive(:run_command).with({:command=>"/sbin/insserv -r -f #{@new_resource.service_name}"})
- @provider.should_receive(:run_command).with({:command=>"/sbin/insserv -d -f #{@new_resource.service_name}"})
+ @provider.should_receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}")
+ @provider.should_receive(:shell_out!).with("/sbin/insserv -d -f #{@new_resource.service_name}")
@provider.enable_service
end
end
describe "disable_service" do
it "should call insserv and remove the links" do
- @provider.should_receive(:run_command).with({:command=>"/sbin/insserv -r -f #{@new_resource.service_name}"})
+ @provider.should_receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}")
@provider.disable_service
end
end
end
-
diff --git a/spec/unit/provider/service/invokercd_service_spec.rb b/spec/unit/provider/service/invokercd_service_spec.rb
index b638b08b72..d8a9851837 100644
--- a/spec/unit/provider/service/invokercd_service_spec.rb
+++ b/spec/unit/provider/service/invokercd_service_spec.rb
@@ -110,7 +110,6 @@ PS
end
-
describe "when we have a 'ps' attribute" do
it "should shell_out! the node's ps command" do
@status = double("Status", :exitstatus => 0, :stdout => @stdout)
@@ -152,12 +151,12 @@ RUNNING_PS
describe "when starting the service" do
it "should call the start command if one is specified" do
@new_resource.start_command("/usr/sbin/invoke-rc.d chef startyousillysally")
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef startyousillysally")
@provider.start_service()
end
it "should call '/usr/sbin/invoke-rc.d service_name start' if no start command is specified" do
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} start")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} start")
@provider.start_service()
end
end
@@ -165,12 +164,12 @@ RUNNING_PS
describe Chef::Provider::Service::Invokercd, "stop_service" do
it "should call the stop command if one is specified" do
@new_resource.stop_command("/usr/sbin/invoke-rc.d chef itoldyoutostop")
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef itoldyoutostop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef itoldyoutostop")
@provider.stop_service()
end
it "should call '/usr/sbin/invoke-rc.d service_name stop' if no stop command is specified" do
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} stop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} stop")
@provider.stop_service()
end
end
@@ -178,13 +177,13 @@ RUNNING_PS
describe "when restarting a service" do
it "should call 'restart' on the service_name if the resource supports it" do
@new_resource.supports({:restart => true})
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restart")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restart")
@provider.restart_service()
end
it "should call the restart_command if one has been specified" do
@new_resource.restart_command("/usr/sbin/invoke-rc.d chef restartinafire")
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restartinafire")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restartinafire")
@provider.restart_service()
end
@@ -199,13 +198,13 @@ RUNNING_PS
describe "when reloading a service" do
it "should call 'reload' on the service if it supports it" do
@new_resource.supports({:reload => true})
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef reload")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef reload")
@provider.reload_service()
end
it "should should run the user specified reload command if one is specified and the service doesn't support reload" do
@new_resource.reload_command("/usr/sbin/invoke-rc.d chef lollerpants")
- @provider.should_receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef lollerpants")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef lollerpants")
@provider.reload_service()
end
end
diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index 1202d80873..c5df1e0637 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -226,7 +226,7 @@ SVC_LIST
it "calls the start command if one is specified and service is not running" do
new_resource.stub(:start_command).and_return("cowsay dirty")
- provider.should_receive(:shell_out!).with("cowsay dirty")
+ provider.should_receive(:shell_out_with_systems_locale!).with("cowsay dirty")
provider.start_service
end
@@ -238,7 +238,7 @@ SVC_LIST
end
it "starts service via launchctl if service found" do
- provider.should_receive(:shell_out!).
+ provider.should_receive(:shell_out_with_systems_locale!).
with("launchctl load -w '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'",
:group => 1001, :user => 101).
and_return(0)
@@ -258,7 +258,7 @@ SVC_LIST
it "calls the stop command if one is specified and service is running" do
new_resource.stub(:stop_command).and_return("kill -9 123")
- provider.should_receive(:shell_out!).with("kill -9 123")
+ provider.should_receive(:shell_out_with_systems_locale!).with("kill -9 123")
provider.stop_service
end
@@ -270,7 +270,7 @@ SVC_LIST
end
it "stops the service via launchctl if service found" do
- provider.should_receive(:shell_out!).
+ provider.should_receive(:shell_out_with_systems_locale!).
with("launchctl unload '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'",
:group => 1001, :user => 101).
and_return(0)
@@ -291,7 +291,7 @@ SVC_LIST
it "issues a command if given" do
new_resource.stub(:restart_command).and_return("reload that thing")
- provider.should_receive(:shell_out!).with("reload that thing")
+ provider.should_receive(:shell_out_with_systems_locale!).with("reload that thing")
provider.restart_service
end
diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb
index 61fb30fe13..11ebf74725 100644
--- a/spec/unit/provider/service/simple_service_spec.rb
+++ b/spec/unit/provider/service/simple_service_spec.rb
@@ -107,7 +107,7 @@ NOMOCKINGSTRINGSPLZ
describe "when starting the service" do
it "should call the start command if one is specified" do
@new_resource.stub(:start_command).and_return("#{@new_resource.start_command}")
- @provider.should_receive(:shell_out!).with("#{@new_resource.start_command}")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("#{@new_resource.start_command}")
@provider.start_service()
end
@@ -121,7 +121,7 @@ NOMOCKINGSTRINGSPLZ
describe "when stopping a service" do
it "should call the stop command if one is specified" do
@new_resource.stop_command("/etc/init.d/themadness stop")
- @provider.should_receive(:shell_out!).with("/etc/init.d/themadness stop")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/themadness stop")
@provider.stop_service()
end
@@ -135,7 +135,7 @@ NOMOCKINGSTRINGSPLZ
describe Chef::Provider::Service::Simple, "restart_service" do
it "should call the restart command if one has been specified" do
@new_resource.restart_command("/etc/init.d/foo restart")
- @provider.should_receive(:shell_out!).with("/etc/init.d/foo restart")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/foo restart")
@provider.restart_service()
end
@@ -162,7 +162,7 @@ NOMOCKINGSTRINGSPLZ
it "should should run the user specified reload command if one is specified" do
@new_resource.reload_command("kill -9 1")
- @provider.should_receive(:shell_out!).with("kill -9 1")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("kill -9 1")
@provider.reload_service()
end
end
diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb
index 978f149258..8df22efa7e 100644
--- a/spec/unit/provider/service/solaris_smf_service_spec.rb
+++ b/spec/unit/provider/service/solaris_smf_service_spec.rb
@@ -59,7 +59,6 @@ describe Chef::Provider::Service::Solaris do
@provider.load_current_resource
end
-
it "should return the current resource" do
@provider.stub(:shell_out!).with("/bin/svcs -l chef").and_return(@status)
@provider.load_current_resource.should eql(@current_resource)
@@ -131,7 +130,6 @@ describe Chef::Provider::Service::Solaris do
end
end
-
describe "when disabling the service" do
before(:each) do
@provider.current_resource = @current_resource
@@ -159,7 +157,7 @@ describe Chef::Provider::Service::Solaris do
end
it "should call svcadm refresh chef" do
- @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm refresh chef").and_return(@status)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/svcadm refresh chef").and_return(@status)
@provider.reload_service
end
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index 2aa7b539f2..7358f63b5e 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -74,25 +74,25 @@ describe Chef::Provider::Service::Systemd do
end
it "should run the services status command if one has been specified" do
- @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_success)
+ @provider.stub(:shell_out).and_return(@shell_out_success)
@current_resource.should_receive(:running).with(true)
@provider.load_current_resource
end
it "should run the services status command if one has been specified and properly set status check state" do
- @provider.stub(:shell_out_with_systems_locale).with("/bin/chefhasmonkeypants status").and_return(@shell_out_success)
+ @provider.stub(:shell_out).with("/bin/chefhasmonkeypants status").and_return(@shell_out_success)
@provider.load_current_resource
@provider.instance_variable_get("@status_check_success").should be_true
end
it "should set running to false if a status command fails" do
- @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_failure)
+ @provider.stub(:shell_out).and_return(@shell_out_failure)
@current_resource.should_receive(:running).with(false)
@provider.load_current_resource
end
it "should update state to indicate status check failed when a status command fails" do
- @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_failure)
+ @provider.stub(:shell_out).and_return(@shell_out_failure)
@provider.load_current_resource
@provider.instance_variable_get("@status_check_success").should be_false
end
@@ -129,31 +129,31 @@ describe Chef::Provider::Service::Systemd do
it "should call the start command if one is specified" do
@new_resource.stub(:start_command).and_return("/sbin/rsyslog startyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally")
@provider.start_service
end
it "should call '/bin/systemctl start service_name' if no start command is specified" do
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl start #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.start_service
end
it "should not call '/bin/systemctl start service_name' if it is already running" do
@current_resource.stub(:running).and_return(true)
- @provider.should_not_receive(:shell_out_with_systems_locale).with("/bin/systemctl start #{@new_resource.service_name}")
+ @provider.should_not_receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}")
@provider.start_service
end
it "should call the restart command if one is specified" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:restart_command).and_return("/sbin/rsyslog restartyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog restartyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog restartyousillysally")
@provider.restart_service
end
it "should call '/bin/systemctl restart service_name' if no restart command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl restart #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl restart #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.restart_service
end
@@ -162,7 +162,7 @@ describe Chef::Provider::Service::Systemd do
it "should call the reload command" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally")
@provider.reload_service
end
end
@@ -170,7 +170,7 @@ describe Chef::Provider::Service::Systemd do
context "when a reload command is not specified" do
it "should call '/bin/systemctl reload service_name' if the service is running" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl reload #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl reload #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.reload_service
end
@@ -185,19 +185,19 @@ describe Chef::Provider::Service::Systemd do
it "should call the stop command if one is specified" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:stop_command).and_return("/sbin/rsyslog stopyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog stopyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog stopyousillysally")
@provider.stop_service
end
it "should call '/bin/systemctl stop service_name' if no stop command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl stop #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.stop_service
end
it "should not call '/bin/systemctl stop service_name' if it is already stopped" do
@current_resource.stub(:running).and_return(false)
- @provider.should_not_receive(:shell_out_with_systems_locale).with("/bin/systemctl stop #{@new_resource.service_name}")
+ @provider.should_not_receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}")
@provider.stop_service
end
end
@@ -210,12 +210,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should call '/bin/systemctl enable service_name' to enable the service" do
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl enable #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out!).with("/bin/systemctl enable #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.enable_service
end
it "should call '/bin/systemctl disable service_name' to disable the service" do
- @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl disable #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.should_receive(:shell_out!).with("/bin/systemctl disable #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.disable_service
end
end
@@ -227,12 +227,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should return true if '/bin/systemctl is-active service_name' returns 0" do
- @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_success)
+ @provider.should_receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_success)
@provider.is_active?.should be_true
end
it "should return false if '/bin/systemctl is-active service_name' returns anything except 0" do
- @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_failure)
+ @provider.should_receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_failure)
@provider.is_active?.should be_false
end
end
@@ -244,12 +244,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should return true if '/bin/systemctl is-enabled service_name' returns 0" do
- @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_success)
+ @provider.should_receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_success)
@provider.is_enabled?.should be_true
end
it "should return false if '/bin/systemctl is-enabled service_name' returns anything except 0" do
- @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_failure)
+ @provider.should_receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_failure)
@provider.is_enabled?.should be_false
end
end
diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb
index efe4e0481f..499a794ff4 100644
--- a/spec/unit/provider/service/upstart_service_spec.rb
+++ b/spec/unit/provider/service/upstart_service_spec.rb
@@ -161,7 +161,6 @@ describe Chef::Provider::Service::Upstart do
@provider.load_current_resource
end
-
it "should track state when the upstart configuration file fails to load" do
File.should_receive(:exists?).and_return false
@provider.load_current_resource
@@ -174,19 +173,19 @@ describe Chef::Provider::Service::Upstart do
end
it "should run the services status command if one has been specified" do
- @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0)
+ @provider.stub(:shell_out!).with("/bin/chefhasmonkeypants status").and_return(0)
@current_resource.should_receive(:running).with(true)
@provider.load_current_resource
end
it "should track state when the user-provided status command fails" do
- @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec)
+ @provider.stub(:shell_out!).and_raise(Errno::ENOENT)
@provider.load_current_resource
@provider.instance_variable_get("@command_success").should == false
end
it "should set running to false if it catches a Chef::Exceptions::Exec when using a status command" do
- @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec)
+ @provider.stub(:shell_out!).and_raise(Errno::ENOENT)
@current_resource.should_receive(:running).with(false)
@provider.load_current_resource
end
@@ -202,7 +201,6 @@ describe Chef::Provider::Service::Upstart do
@provider.load_current_resource.should eql(@current_resource)
end
-
end
describe "enable and disable service" do
@@ -243,18 +241,18 @@ describe Chef::Provider::Service::Upstart do
it "should call the start command if one is specified" do
@new_resource.stub(:start_command).and_return("/sbin/rsyslog startyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog startyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally")
@provider.start_service()
end
it "should call '/sbin/start service_name' if no start command is specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/start #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0)
@provider.start_service()
end
it "should not call '/sbin/start service_name' if it is already running" do
@current_resource.stub(:running).and_return(true)
- @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/sbin/start #{@new_resource.service_name}"})
+ @provider.should_not_receive(:shell_out_with_systems_locale!)
@provider.start_service()
end
@@ -263,58 +261,58 @@ describe Chef::Provider::Service::Upstart do
@new_resource.parameters({ "OSD_ID" => "2" })
@provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context)
@provider.current_resource = @current_resource
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/start rsyslog OSD_ID=2"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start rsyslog OSD_ID=2").and_return(0)
@provider.start_service()
end
it "should call the restart command if one is specified" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:restart_command).and_return("/sbin/rsyslog restartyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog restartyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog restartyousillysally")
@provider.restart_service()
end
it "should call '/sbin/restart service_name' if no restart command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/restart #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/restart #{@new_resource.service_name}").and_return(0)
@provider.restart_service()
end
it "should call '/sbin/start service_name' if restart_service is called for a stopped service" do
@current_resource.stub(:running).and_return(false)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/start #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0)
@provider.restart_service()
end
it "should call the reload command if one is specified" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally")
@provider.reload_service()
end
it "should call '/sbin/reload service_name' if no reload command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/reload #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/reload #{@new_resource.service_name}").and_return(0)
@provider.reload_service()
end
it "should call the stop command if one is specified" do
@current_resource.stub(:running).and_return(true)
@new_resource.stub(:stop_command).and_return("/sbin/rsyslog stopyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog stopyousillysally")
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog stopyousillysally")
@provider.stop_service()
end
it "should call '/sbin/stop service_name' if no stop command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/stop #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}").and_return(0)
@provider.stop_service()
end
it "should not call '/sbin/stop service_name' if it is already stopped" do
@current_resource.stub(:running).and_return(false)
- @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/sbin/stop #{@new_resource.service_name}"})
+ @provider.should_not_receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}")
@provider.stop_service()
end
end
diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb
index f37a42d235..5d9d1cec1e 100644
--- a/spec/unit/provider/subversion_spec.rb
+++ b/spec/unit/provider/subversion_spec.rb
@@ -16,7 +16,6 @@
# limitations under the License.
#
-
require 'spec_helper'
describe Chef::Provider::Subversion do
@@ -199,7 +198,7 @@ describe Chef::Provider::Subversion do
it "runs an export with the --force option" do
::File.stub(:directory?).with("/my/deploy").and_return(true)
expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
- @provider.should_receive(:run_command).with(:command => expected_cmd)
+ @provider.should_receive(:shell_out!).with(command: expected_cmd)
@provider.run_action(:force_export)
@resource.should be_updated
end
@@ -207,7 +206,7 @@ describe Chef::Provider::Subversion do
it "runs the checkout command for action_checkout" do
::File.stub(:directory?).with("/my/deploy").and_return(true)
expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
- @provider.should_receive(:run_command).with(:command => expected_cmd)
+ @provider.should_receive(:shell_out!).with(command: expected_cmd)
@provider.run_action(:checkout)
@resource.should be_updated
end
@@ -231,7 +230,7 @@ describe Chef::Provider::Subversion do
@resource.user "whois"
@resource.group "thisis"
expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
- @provider.should_receive(:run_command).with(:command => expected_cmd, :user => "whois", :group => "thisis")
+ @provider.should_receive(:shell_out!).with(command: expected_cmd, user: "whois", group: "thisis")
@provider.run_action(:checkout)
@resource.should be_updated
end
@@ -256,7 +255,7 @@ describe Chef::Provider::Subversion do
@provider.stub(:find_current_revision).and_return("11410")
@provider.stub(:current_revision_matches_target_revision?).and_return(false)
expected_cmd = "svn update -q -r12345 /my/deploy/dir"
- @provider.should_receive(:run_command).with(:command => expected_cmd)
+ @provider.should_receive(:shell_out!).with(command: expected_cmd)
@provider.run_action(:sync)
@resource.should be_updated
end
@@ -273,7 +272,7 @@ describe Chef::Provider::Subversion do
it "runs the export_command on action_export" do
::File.stub(:directory?).with("/my/deploy").and_return(true)
expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir"
- @provider.should_receive(:run_command).with(:command => expected_cmd)
+ @provider.should_receive(:shell_out!).with(command: expected_cmd)
@provider.run_action(:export)
@resource.should be_updated
end
diff --git a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb
index 5a17aacbd9..d5209248b3 100644
--- a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb
+++ b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb
@@ -30,14 +30,14 @@ describe Chef::Provider::WhyrunSafeRubyBlock, "initialize" do
end
it "should call the block and flag the resource as updated" do
- @provider.run_action(:create)
+ @provider.run_action(:run)
$evil_global_evil_laugh.should == :mwahahaha
@new_resource.should be_updated
end
it "should call the block and flat the resource as updated - even in whyrun" do
Chef::Config[:why_run] = true
- @provider.run_action(:create)
+ @provider.run_action(:run)
$evil_global_evil_laugh.should == :mwahahaha
@new_resource.should be_updated
Chef::Config[:why_run] = false
diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb
index 1def10faf5..21ece2abaa 100644
--- a/spec/unit/run_context_spec.rb
+++ b/spec/unit/run_context_spec.rb
@@ -134,4 +134,19 @@ describe Chef::RunContext do
end
end
+ describe "handling reboot requests" do
+ let(:expected) do
+ { :reason => "spec tests require a reboot" }
+ end
+
+ it "stores and deletes the reboot request" do
+ @run_context.request_reboot(expected)
+ expect(@run_context.reboot_info).to eq(expected)
+ expect(@run_context.reboot_requested?).to be_true
+
+ @run_context.cancel_reboot
+ expect(@run_context.reboot_info).to eq({})
+ expect(@run_context.reboot_requested?).to be_false
+ end
+ end
end
diff --git a/spec/unit/workstation_config_loader_spec.rb b/spec/unit/workstation_config_loader_spec.rb
index 78313aec37..d1e352602d 100644
--- a/spec/unit/workstation_config_loader_spec.rb
+++ b/spec/unit/workstation_config_loader_spec.rb
@@ -88,7 +88,12 @@ describe Chef::WorkstationConfigLoader do
let(:env_pwd) { "/path/to/cwd" }
before do
- env["PWD"] = env_pwd
+ if Chef::Platform.windows?
+ env["CD"] = env_pwd
+ else
+ env["PWD"] = env_pwd
+ end
+
allow(config_loader).to receive(:path_exists?).with("#{env_pwd}/.chef/knife.rb").and_return(true)
allow(File).to receive(:exist?).with("#{env_pwd}/.chef").and_return(true)
allow(File).to receive(:directory?).with("#{env_pwd}/.chef").and_return(true)
@@ -229,7 +234,8 @@ describe Chef::WorkstationConfigLoader do
let(:config_content) { "" }
let(:explicit_config_location) do
- t = Tempfile.new("#{described_class}-rspec-test")
+ # could use described_class, but remove all ':' from the path if so.
+ t = Tempfile.new("Chef-WorkstationConfigLoader-rspec-test")
t.print(config_content)
t.close
t.path