summaryrefslogtreecommitdiff
path: root/spec/integration/recipes
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-12-10 09:18:15 -0800
committerJohn Keiser <john@johnkeiser.com>2015-12-10 14:55:20 -0800
commit1910740592068982a4b6f9ee58452375d60281d5 (patch)
tree58e358d3911f769ea3052a14b8e1bc2747b56378 /spec/integration/recipes
parentd8a869814a0cbe1a44ee47e5c3ac1802a8fef2f2 (diff)
downloadchef-1910740592068982a4b6f9ee58452375d60281d5.tar.gz
Warn when user sets a property of an inline resource to itself.
(User will expect "x x" to grab the parent property.)
Diffstat (limited to 'spec/integration/recipes')
-rw-r--r--spec/integration/recipes/resource_action_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb
index 6f3f5ab47e..26ce54a1c5 100644
--- a/spec/integration/recipes/resource_action_spec.rb
+++ b/spec/integration/recipes/resource_action_spec.rb
@@ -360,4 +360,54 @@ describe "Resource.action" do
expect(WeirdActionJackson.action_was).to eq :"a-b-c d"
end
end
+
+ context "With a resource with property x" do
+ class ResourceActionSpecWithX < Chef::Resource
+ resource_name :resource_action_spec_with_x
+ property :x, default: 20
+ action :set do
+ # Access x during converge to ensure that we emit no warnings there
+ x
+ end
+ end
+
+ context "And another resource with a property x and an action that sets property x to its value" do
+ class ResourceActionSpecAlsoWithX < Chef::Resource
+ resource_name :resource_action_spec_also_with_x
+ property :x
+ action :set_x_to_x do
+ resource_action_spec_with_x 'hi' do
+ x x
+ end
+ end
+ action :set_x_to_10 do
+ resource_action_spec_with_x 'hi' do
+ x 10
+ end
+ end
+ end
+
+ it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do
+ recipe = converge {
+ resource_action_spec_also_with_x 'hi' do
+ x 1
+ action :set_x_to_x
+ end
+ }
+ warnings = recipe.logs.lines.select { |l| l =~ /warn/i }
+ expect(warnings.size).to eq 1
+ expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{__LINE__-19}/)
+ end
+
+ it "Using the enclosing resource to set x to 10 emits no warning" do
+ expect_recipe {
+ resource_action_spec_also_with_x 'hi' do
+ x 1
+ action :set_x_to_10
+ end
+ }.to emit_no_warnings_or_errors
+ end
+ end
+
+ end
end