summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-07-06 12:51:22 -0600
committerJohn Keiser <john@johnkeiser.com>2015-07-06 12:51:22 -0600
commitcb163f4b69e0378b9dc4c60b935b891e05706ccc (patch)
tree2281db33b9d5e2dc40d2f4f13512ca69882f8adf
parentc6d3fd81db9bab3bbd95e42c0d20d8218b6d8aa0 (diff)
downloadchef-cb163f4b69e0378b9dc4c60b935b891e05706ccc.tar.gz
Don't accept multiple parameters in recipe DSL (just name)
-rw-r--r--lib/chef/dsl/resources.rb8
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb20
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb
index 1ce12ed0a0..c634c6520d 100644
--- a/lib/chef/dsl/resources.rb
+++ b/lib/chef/dsl/resources.rb
@@ -10,14 +10,14 @@ class Chef
def self.add_resource_dsl(dsl_name)
begin
module_eval(<<-EOM, __FILE__, __LINE__+1)
- def #{dsl_name}(name=nil, created_at=nil, &block)
- declare_resource(#{dsl_name.inspect}, name, created_at || caller[0], &block)
+ def #{dsl_name}(name=nil, &block)
+ declare_resource(#{dsl_name.inspect}, name, caller[0], &block)
end
EOM
rescue SyntaxError
# Handle the case where dsl_name has spaces, etc.
- define_method(dsl_name.to_sym) do |name=nil, created_at=nil, &block|
- declare_resource(dsl_name, name, created_at || caller[0], &block)
+ define_method(dsl_name.to_sym) do |name=nil, &block|
+ declare_resource(dsl_name, name, caller[0], &block)
end
end
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 4e80c5a738..1ab01fb20e 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -47,6 +47,26 @@ describe "Recipe DSL methods" do
BaseThingy.created_provider = nil
end
+ it "creates base_thingy when you call base_thingy in a recipe" do
+ recipe = converge {
+ base_thingy 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq BaseThingy
+ end
+
+ it "errors out when you call base_thingy do ... end in a recipe" do
+ expect_converge {
+ base_thingy do; end
+ }.to raise_error(ArgumentError, 'You must supply a name when declaring a base_thingy resource')
+ end
+
+ it "errors out when you call base_thingy 'foo', 'bar' do ... end in a recipe" do
+ expect_converge {
+ base_thingy 'foo', 'bar' do; end
+ }.to raise_error(ArgumentError, 'wrong number of arguments (2 for 0..1)')
+ end
+
context "Deprecated automatic resource DSL" do
before do
Chef::Config[:treat_deprecation_warnings_as_errors] = false