diff options
author | John Keiser <john@johnkeiser.com> | 2015-10-28 20:52:28 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-10-28 20:52:28 -0700 |
commit | 571891bf67667d0240edd632c36fc84cd0fc8bbe (patch) | |
tree | b7e9c4397a7b1c79789d3350f2407ebd25ded7ec /spec | |
parent | f01f65150cbc21e9a42f42c444d430320aa8ba5a (diff) | |
download | chef-571891bf67667d0240edd632c36fc84cd0fc8bbe.tar.gz |
Make Property.derive create derived properties of the same typejk/custom_properties
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/property_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index dc06cb3326..095dcc8e98 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -1099,4 +1099,52 @@ describe "Chef::Resource.property" do expect { resource_class.property :x, :name_property => true, :name_attribute => true }.to raise_error ArgumentError, /Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./ end + + context "with a custom property type" do + class CustomPropertyType < Chef::Property + end + + with_property ":x, CustomPropertyType.new" do + it "creates x with the given type" do + expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType) + end + + context "and a subclass" do + let(:subresource_class) do + new_resource_name = self.class.new_resource_name + Class.new(resource_class) do + resource_name new_resource_name + end + end + let(:subresource) do + subresource_class.new('blah') + end + + context "with property :x, default: 10 on the subclass" do + before do + subresource_class.class_eval do + property :x, default: 10 + end + end + + it "x has the given type and default on the subclass" do + expect(subresource_class.properties[:x]).to be_kind_of(CustomPropertyType) + expect(subresource_class.properties[:x].default).to eq(10) + end + + it "x does not have the default on the superclass" do + expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType) + expect(resource_class.properties[:x].default).to be_nil + end + end + end + end + + with_property ":x, CustomPropertyType.new, default: 10" do + it "passes the default to the custom property type" do + expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType) + expect(resource_class.properties[:x].default).to eq(10) + end + end + end end |