diff options
Diffstat (limited to 'spec/unit/resource')
-rw-r--r-- | spec/unit/resource/conditional_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb index b34b4200e6..e84b0980c4 100644 --- a/spec/unit/resource/conditional_spec.rb +++ b/spec/unit/resource/conditional_spec.rb @@ -124,6 +124,29 @@ describe Chef::Resource::Conditional do expect(@conditional.continue?).to be_falsey end end + + describe "after running a block that returns a string value" do + before do + @conditional = Chef::Resource::Conditional.only_if(@parent_resource) { "some command" } + end + + it "logs a warning" do + expect(Chef::Log).to receive(:warn).with("only_if block for [] returned \"some command\", did you mean to run a command? If so use 'only_if \"some command\"' in your code.") + @conditional.evaluate + end + end + + describe "after running a block that returns a string value on a sensitive resource" do + before do + @parent_resource.sensitive(true) + @conditional = Chef::Resource::Conditional.only_if(@parent_resource) { "some command" } + end + + it "logs a warning" do + expect(Chef::Log).to receive(:warn).with("only_if block for [] returned a string, did you mean to run a command?") + @conditional.evaluate + end + end end describe "when created as a `not_if`" do @@ -204,5 +227,28 @@ describe Chef::Resource::Conditional do expect(@conditional.continue?).to be_truthy end end + + describe "after running a block that returns a string value" do + before do + @conditional = Chef::Resource::Conditional.not_if(@parent_resource) { "some command" } + end + + it "logs a warning" do + expect(Chef::Log).to receive(:warn).with("not_if block for [] returned \"some command\", did you mean to run a command? If so use 'not_if \"some command\"' in your code.") + @conditional.evaluate + end + end + + describe "after running a block that returns a string value on a sensitive resource" do + before do + @parent_resource.sensitive(true) + @conditional = Chef::Resource::Conditional.not_if(@parent_resource) { "some command" } + end + + it "logs a warning" do + expect(Chef::Log).to receive(:warn).with("not_if block for [] returned a string, did you mean to run a command?") + @conditional.evaluate + end + end end end |