diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-03-19 13:51:33 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-03-19 13:51:33 -0700 |
commit | 9a8bf0ec8eddc4e009da989fa00e8bbe6fa65277 (patch) | |
tree | 3bb5874cd5108cc0b95407592db0008f31104ceb /spec/unit/cookbook | |
parent | 50ed576ca81a22d9d489ba983e1641f01e8e280b (diff) | |
parent | 24eab5026e5b6aca87089415e80deccf40c6395c (diff) | |
download | chef-9a8bf0ec8eddc4e009da989fa00e8bbe6fa65277.tar.gz |
Merge pull request #1245 from slantview/CHEF-4075
Update to allow boolean and numeric attributes
Diffstat (limited to 'spec/unit/cookbook')
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index cba2aff5da..88c4a1a5f5 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -402,7 +402,7 @@ describe Chef::Cookbook::Metadata do @meta.attributes["db/mysql/databases"][:recipes].should == [] end - it "should allow the default value to be a string, array, or hash" do + it "should allow the default value to be a string, array, hash, boolean or numeric" do lambda { @meta.attribute("db/mysql/databases", :default => []) }.should_not raise_error @@ -413,10 +413,54 @@ describe Chef::Cookbook::Metadata do @meta.attribute("db/mysql/databases", :default => "alice in chains") }.should_not raise_error lambda { + @meta.attribute("db/mysql/databases", :default => 1337) + }.should_not raise_error + lambda { + @meta.attribute("db/mysql/databases", :default => true) + }.should_not raise_error + lambda { @meta.attribute("db/mysql/databases", :required => :not_gonna_do_it) }.should raise_error(ArgumentError) end + it "should limit the types allowed in the choice array" do + options = { + :type => "string", + :choice => [ "test1", "test2" ], + :default => "test1" + } + lambda { + @meta.attribute("test_cookbook/test", options) + }.should_not raise_error + + options = { + :type => "boolean", + :choice => [ true, false ], + :default => true + } + lambda { + @meta.attribute("test_cookbook/test", options) + }.should_not raise_error + + options = { + :type => "numeric", + :choice => [ 1337, 420 ], + :default => 1337 + } + lambda { + @meta.attribute("test_cookbook/test", options) + }.should_not raise_error + + options = { + :type => "numeric", + :choice => [ true, "false" ], + :default => false + } + lambda { + @meta.attribute("test_cookbook/test", options) + }.should raise_error + end + it "should error if default used with calculated" do lambda { attrs = { |