diff options
-rw-r--r-- | chef/lib/chef/provider/ruby_block.rb | 12 | ||||
-rw-r--r-- | chef/spec/unit/provider/ruby_block_spec.rb | 16 |
2 files changed, 21 insertions, 7 deletions
diff --git a/chef/lib/chef/provider/ruby_block.rb b/chef/lib/chef/provider/ruby_block.rb index 1924e2f83b..5b259a0215 100644 --- a/chef/lib/chef/provider/ruby_block.rb +++ b/chef/lib/chef/provider/ruby_block.rb @@ -29,15 +29,13 @@ class Chef end def action_create - if @new_resource.whyrun_safe + description = "execute the ruby block #{@new_resource.name}" + if Chef::Config[:why_run] && @new_resource.whyrun_safe @new_resource.block.call - if Chef::Config[:why_run] - Chef::Log.info("#{@new_resource} called - labelled as whyrun-safe") - else - Chef::Log.info("#{@new_resource} called") - end + new_resource.updated_by_last_action(true) + Chef::Log.info("#{@new_resource} called - labelled as whyrun-safe") else - converge_by("execute the ruby block #{@new_resource.name}") do + converge_by(description) do @new_resource.block.call Chef::Log.info("#{@new_resource} called") end diff --git a/chef/spec/unit/provider/ruby_block_spec.rb b/chef/spec/unit/provider/ruby_block_spec.rb index 7efb4c7fcd..bb9d2e06cd 100644 --- a/chef/spec/unit/provider/ruby_block_spec.rb +++ b/chef/spec/unit/provider/ruby_block_spec.rb @@ -34,5 +34,21 @@ describe Chef::Provider::RubyBlock, "initialize" do $evil_global_evil_laugh.should == :mwahahaha @new_resource.should be_updated end + + it "should call why-run safe blocks in whyrun mode" do + Chef::Config[:why_run] = true + @new_resource.whyrun_safe(true) + @provider.run_action(:create) + $evil_global_evil_laugh.should == :mwahahaha + @new_resource.should be_updated + end + + it "should not call non-why-run safe blocks in whyrun mode" do + Chef::Config[:why_run] = true + @provider.run_action(:create) + $evil_global_evil_laugh.should == :wahwah + @new_resource.should be_updated + end + end |