summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2015-02-13 09:45:57 -0800
committertyler-ball <tyleraball@gmail.com>2015-02-13 15:57:18 -0800
commita5f29b1245cfeb5b726bed373331f34014c6199b (patch)
tree292c32fddeafda71855ac130a9903a472a235dc8
parentbf0240b07f00348d4cb60e72c955e0bc3982abda (diff)
downloadchef-a5f29b1245cfeb5b726bed373331f34014c6199b.tar.gz
Completeting changes from https://github.com/chef/chef/pull/2688, fixes https://github.com/chef/chef/issues/2683
-rw-r--r--lib/chef/guard_interpreter/resource_guard_interpreter.rb2
-rw-r--r--spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb33
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
index 7d9bccb6ca..fb545c95eb 100644
--- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
@@ -41,7 +41,7 @@ class Chef
# attribute by checking the type of the resources.
# We need to make sure we check for Script first because any resource
# that can get to here is an Execute resource.
- if @parent_resource.is_a? Chef::Resource::Script
+ if @resource.is_a? Chef::Resource::Script
block_attributes = @command_opts.merge({:code => @command})
else
block_attributes = @command_opts.merge({:command => @command})
diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
index 1eddd54b6a..4cf3ba827a 100644
--- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
+++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb
@@ -83,21 +83,34 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
expect(guard_interpreter.evaluate).to eq(true)
end
- describe "Script command opts switch" do
+ describe "script command opts switch" do
let(:command_opts) { {} }
- let(:guard_interpreter) { Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource, "echo hi", command_opts) }
+ let(:guard_interpreter) { Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource, "exit 0", command_opts) }
context "resource is a Script" do
- context "and guard_interpreter is :script" do
+ context "and guard_interpreter is a :script" do
let(:parent_resource) do
parent_resource = Chef::Resource::Script.new("resource", run_context)
- parent_resource.guard_interpreter(:script)
+ # Ruby scripts are cross platform to both Linux and Windows
+ parent_resource.guard_interpreter(:ruby)
parent_resource
end
+ let(:shell_out) {
+ instance_double(Mixlib::ShellOut, :live_stream => true, :run_command => true, :error! => nil)
+ }
+
+ before do
+ # TODO for some reason Windows is failing on executing a ruby script
+ expect(Mixlib::ShellOut).to receive(:new) do |*args|
+ expect(args[0]).to match(/^"ruby"/)
+ shell_out
+ end
+ end
+
it "merges to :code" do
- expect(command_opts).to receive(:merge).with({:code => "echo hi"}).and_call_original
- guard_interpreter.evaluate
+ expect(command_opts).to receive(:merge).with({:code => "exit 0"}).and_call_original
+ expect(guard_interpreter.evaluate).to eq(true)
end
end
@@ -109,8 +122,8 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
end
it "merges to :code" do
- expect(command_opts).to receive(:merge).with({:command => "echo hi"}).and_call_original
- guard_interpreter.evaluate
+ expect(command_opts).to receive(:merge).with({:command => "exit 0"}).and_call_original
+ expect(guard_interpreter.evaluate).to eq(true)
end
end
end
@@ -123,8 +136,8 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do
end
it "merges to :command" do
- expect(command_opts).to receive(:merge).with({:command => "echo hi"}).and_call_original
- guard_interpreter.evaluate
+ expect(command_opts).to receive(:merge).with({:command => "exit 0"}).and_call_original
+ expect(guard_interpreter.evaluate).to eq(true)
end
end