summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2013-11-14 22:40:57 -0800
committerPhil Dibowitz <phil@ipom.com>2013-11-21 12:56:52 -0800
commit24966183ec136d911144e51dabe743eeb2e43ef4 (patch)
tree8b4158ecfe3d1452c65514b52c8f4203ff8ef17d
parent843f5e91668df5f42f56937cd84549301b839165 (diff)
downloadchef-24966183ec136d911144e51dabe743eeb2e43ef4.tar.gz
Add test for whyrun-safe in ruby blocks
Also refactor the code to be slightly cleaner and fix 'updated' bug.
-rw-r--r--chef/lib/chef/provider/ruby_block.rb12
-rw-r--r--chef/spec/unit/provider/ruby_block_spec.rb16
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