diff options
author | Bryan McLellan <btm@loftninjas.org> | 2014-09-11 14:20:51 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2014-09-30 20:13:17 -0400 |
commit | d23eb2cdbdb2a9f49653426756c1d84cb2cab4be (patch) | |
tree | 04ce345d519f9020cbc20ef47aa71f4d44191894 | |
parent | b663f070786ad004fc2d8a71699a3d30abdd9f6d (diff) | |
download | chef-d23eb2cdbdb2a9f49653426756c1d84cb2cab4be.tar.gz |
guard_interpreter requires a command
Raises an exception if guard_interpreter is set (not :default) and we are not
given a command (i.e. we are given a block). This is not supported, as we pass
a command to an external interpreter.
Related to #1943
-rw-r--r-- | lib/chef/resource/conditional.rb | 5 | ||||
-rw-r--r-- | spec/unit/resource/conditional_spec.rb | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/chef/resource/conditional.rb b/lib/chef/resource/conditional.rb index e6623be5dd..ad082c82d1 100644 --- a/lib/chef/resource/conditional.rb +++ b/lib/chef/resource/conditional.rb @@ -52,6 +52,11 @@ class Chef @block = nil when nil raise ArgumentError, "only_if/not_if requires either a command or a block" unless block_given? + if parent_resource.guard_interpreter != :default + msg = "#{parent_resource.name} was given a guard_interpreter of #{parent_resource.guard_interpreter}, " + msg << "but not given a command as a string. guard_interpreter does not support blocks." + raise ArgumentError, msg + end @guard_interpreter = nil @command, @command_opts = nil, nil @block = block diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb index 4df185bcd6..92ca53118b 100644 --- a/spec/unit/resource/conditional_spec.rb +++ b/spec/unit/resource/conditional_spec.rb @@ -27,6 +27,15 @@ describe Chef::Resource::Conditional do @parent_resource = Chef::Resource.new(nil, Chef::Node.new) end + it "raises an exception when a guard_interpreter is specified and a block is given" do + @parent_resource.guard_interpreter :canadian_mounties + expect { Chef::Resource::Conditional.send(:new, :always, @parent_resource, nil, {}) { True } }.to raise_error(ArgumentError, /does not support blocks/) + end + + it "raises an exception when neither a block or command is given" do + expect { Chef::Resource::Conditional.send(:new, :always, @parent_resource, nil, {})}.to raise_error(ArgumentError, /requires either a command or a block/) + end + describe "when created as an `only_if`" do describe "after running a successful command" do before do |