summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-09-25 21:01:57 -0400
committerBryan McLellan <btm@loftninjas.org>2014-09-30 20:13:31 -0400
commit3eb618e7826115c3be40d68b072adea7e5b0248e (patch)
tree5191138f96ad0dd86124e959c161316e79c95c02
parent906b6cc2dd59c001955a6d8e7dc26296c6663539 (diff)
downloadchef-3eb618e7826115c3be40d68b072adea7e5b0248e.tar.gz
unit test for guard_interpreter creation during compilation
make sure we don't evaluate the guard_interpreter immediately, i.e. during compilation of the resource, as the conditional may be seen before the guard_interpreter attribute.
-rw-r--r--lib/chef/resource/conditional.rb1
-rw-r--r--spec/unit/resource/conditional_spec.rb7
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/chef/resource/conditional.rb b/lib/chef/resource/conditional.rb
index d188e2ad0b..140078d39a 100644
--- a/lib/chef/resource/conditional.rb
+++ b/lib/chef/resource/conditional.rb
@@ -72,6 +72,7 @@ class Chef
end
end
+ # this is run during convergence via Chef::Resource#run_action -> Chef::Resource#should_skip?
def continue?
# configure late in case guard_interpreter is specified on the resource after the conditional
configure
diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb
index 92ca53118b..8d0fae18f0 100644
--- a/spec/unit/resource/conditional_spec.rb
+++ b/spec/unit/resource/conditional_spec.rb
@@ -36,6 +36,13 @@ describe Chef::Resource::Conditional do
expect { Chef::Resource::Conditional.send(:new, :always, @parent_resource, nil, {})}.to raise_error(ArgumentError, /requires either a command or a block/)
end
+ it "does not evaluate a guard interpreter on initialization of the conditional" do
+ expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:configure)
+ expect(Chef::GuardInterpreter::DefaultGuardInterpreter).not_to receive(:new)
+ expect(Chef::GuardInterpreter::ResourceGuardInterpreter).not_to receive(:new)
+ Chef::Resource::Conditional.only_if(@parent_resource, "true")
+ end
+
describe "when created as an `only_if`" do
describe "after running a successful command" do
before do