summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-04 10:43:38 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-23 15:23:02 -0700
commitf47252a75191d96e169abdc7c9d84aa6e50df708 (patch)
tree45dcb92ca96ff5b1881bc227236e81a86a3e946a /spec
parent2d7f1282c63ca6480f363603608e9d3cdf38116e (diff)
downloadchef-f47252a75191d96e169abdc7c9d84aa6e50df708.tar.gz
Add property_is_set?
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/property/state_spec.rb56
-rw-r--r--spec/unit/property_spec.rb188
2 files changed, 119 insertions, 125 deletions
diff --git a/spec/unit/property/state_spec.rb b/spec/unit/property/state_spec.rb
index d5c0893cfd..80ebe01a41 100644
--- a/spec/unit/property/state_spec.rb
+++ b/spec/unit/property/state_spec.rb
@@ -194,45 +194,39 @@ describe "Chef::Resource#identity and #state" do
before do
resource_class.class_eval do
def custom_property
- @blarghle*3
+ @blarghle ? @blarghle*3 : nil
end
def custom_property=(x)
@blarghle = x*2
end
end
+ end
- context "And identity_attr :custom_property" do
- before do
- resource_class.class_eval do
- identity_attr :custom_property
- end
+ context "And identity_attr :custom_property" do
+ before do
+ resource_class.class_eval do
+ identity_attr :custom_property
end
+ end
- it "identity_attr comes back as :custom_property" do
- # expect(resource_class.properties[:custom_property].identity?).to be_truthy
- expect(resource_class.identity_attr).to eq :custom_property
- end
- it "custom_property becomes part of desired_state" do
- # expect(resource_class.properties[:custom_property].desired_state?).to be_truthy
- expect(resource_class.state_attrs).to eq [ :custom_property ]
- end
- it "identity_attr does not change custom_property's getter or setter" do
- expect(resource.custom_property = 1).to eq 2
- expect(resource.custom_property).to eq 6
- end
- it "custom_property is returned as the identity" do
- expect(resource_class.identity_attr).to
- expect(resource.identity).to be_nil
- resource.custom_property = 1
- expect(resource.identity).to eq 6
- end
- it "custom_property is part of desired state" do
- resource.custom_property = 1
- expect(resource.state).to eq({ custom_property: 6 })
- end
- it "property_is_set?(:custom_property) returns true even if it hasn't been set" do
- expect(resource.property_is_set?(:custom_property)).to be_truthy
- end
+ it "identity_attr comes back as :custom_property" do
+ # expect(resource_class.properties[:custom_property].identity?).to be_truthy
+ expect(resource_class.identity_attr).to eq :custom_property
+ end
+ # it "custom_property becomes part of desired_state" do
+ # resource.custom_property = 1
+ # expect(resource.state).to eq({ custom_property: 6 })
+ # expect(resource_class.properties[:custom_property].desired_state?).to be_truthy
+ # expect(resource_class.state_attrs).to eq [ :custom_property ]
+ # end
+ it "identity_attr does not change custom_property's getter or setter" do
+ resource.custom_property = 1
+ expect(resource.custom_property).to eq 6
+ end
+ it "custom_property is returned as the identity" do
+ expect(resource.identity).to be_nil
+ resource.custom_property = 1
+ expect(resource.identity).to eq 6
end
end
end
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 152bad9bc0..83ce3762c7 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -212,105 +212,105 @@ describe "Chef::Resource.property" do
end
end
- # context "Chef::Resource::PropertyType#property_is_set?" do
- # it "when a resource is newly created, property_is_set?(:name) is true" do
- # expect(resource.property_is_set?(:name)).to be_truthy
- # end
- #
- # it "when referencing an undefined property, property_is_set?(:x) raises an error" do
- # expect { resource.property_is_set?(:x) }.to raise_error(ArgumentError)
- # end
- #
- # with_property ':x' do
- # it "when the resource is newly created, property_is_set?(:x) is false" do
- # expect(resource.property_is_set?(:x)).to be_falsey
- # end
- # it "when x is set, property_is_set?(:x) is true" do
- # resource.x 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set with =, property_is_set?(:x) is true" do
- # resource.x = 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set to a lazy value, property_is_set?(:x) is true" do
- # resource.x lazy { 10 }
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is retrieved, property_is_set?(:x) is false" do
- # resource.x
- # expect(resource.property_is_set?(:x)).to be_falsey
- # end
- # end
- #
- # with_property ':x, default: 10' do
- # it "when the resource is newly created, property_is_set?(:x) is false" do
- # expect(resource.property_is_set?(:x)).to be_falsey
- # end
- # it "when x is set, property_is_set?(:x) is true" do
- # resource.x 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set with =, property_is_set?(:x) is true" do
- # resource.x = 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set to a lazy value, property_is_set?(:x) is true" do
- # resource.x lazy { 10 }
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is retrieved, property_is_set?(:x) is true" do
- # resource.x
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # end
- #
- # with_property ':x, default: nil' do
- # it "when the resource is newly created, property_is_set?(:x) is false" do
- # expect(resource.property_is_set?(:x)).to be_falsey
- # end
- # it "when x is set, property_is_set?(:x) is true" do
- # resource.x 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set with =, property_is_set?(:x) is true" do
- # resource.x = 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set to a lazy value, property_is_set?(:x) is true" do
- # resource.x lazy { 10 }
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is retrieved, property_is_set?(:x) is true" do
- # resource.x
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # end
- #
- # with_property ':x, default: lazy { 10 }' do
- # it "when the resource is newly created, property_is_set?(:x) is false" do
- # expect(resource.property_is_set?(:x)).to be_falsey
- # end
- # it "when x is set, property_is_set?(:x) is true" do
- # resource.x 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is set with =, property_is_set?(:x) is true" do
- # resource.x = 10
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # it "when x is retrieved, property_is_set?(:x) is true" do
- # resource.x
- # expect(resource.property_is_set?(:x)).to be_truthy
- # end
- # end
- # end
+ context "Chef::Resource::PropertyType#property_is_set?" do
+ it "when a resource is newly created, property_is_set?(:name) is true" do
+ expect(resource.property_is_set?(:name)).to be_truthy
+ end
+
+ # it "when referencing an undefined property, property_is_set?(:x) raises an error" do
+ # expect { resource.property_is_set?(:x) }.to raise_error(ArgumentError)
+ # end
+
+ with_property ':x' do
+ it "when the resource is newly created, property_is_set?(:x) is false" do
+ expect(resource.property_is_set?(:x)).to be_falsey
+ end
+ it "when x is set, property_is_set?(:x) is true" do
+ resource.x 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set with =, property_is_set?(:x) is true" do
+ resource.x = 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set to a lazy value, property_is_set?(:x) is true" do
+ resource.x lazy { 10 }
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is retrieved, property_is_set?(:x) is false" do
+ resource.x
+ expect(resource.property_is_set?(:x)).to be_falsey
+ end
+ end
+
+ with_property ':x, default: 10' do
+ it "when the resource is newly created, property_is_set?(:x) is false" do
+ expect(resource.property_is_set?(:x)).to be_falsey
+ end
+ it "when x is set, property_is_set?(:x) is true" do
+ resource.x 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set with =, property_is_set?(:x) is true" do
+ resource.x = 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set to a lazy value, property_is_set?(:x) is true" do
+ resource.x lazy { 10 }
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is retrieved, property_is_set?(:x) is true" do
+ resource.x
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ end
+
+ with_property ':x, default: nil' do
+ it "when the resource is newly created, property_is_set?(:x) is false" do
+ expect(resource.property_is_set?(:x)).to be_falsey
+ end
+ it "when x is set, property_is_set?(:x) is true" do
+ resource.x 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set with =, property_is_set?(:x) is true" do
+ resource.x = 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set to a lazy value, property_is_set?(:x) is true" do
+ resource.x lazy { 10 }
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is retrieved, property_is_set?(:x) is true" do
+ resource.x
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ end
+
+ with_property ':x, default: lazy { 10 }' do
+ it "when the resource is newly created, property_is_set?(:x) is false" do
+ expect(resource.property_is_set?(:x)).to be_falsey
+ end
+ it "when x is set, property_is_set?(:x) is true" do
+ resource.x 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is set with =, property_is_set?(:x) is true" do
+ resource.x = 10
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ it "when x is retrieved, property_is_set?(:x) is true" do
+ resource.x
+ expect(resource.property_is_set?(:x)).to be_truthy
+ end
+ end
+ end
context "Chef::Resource::PropertyType#default" do
with_property ':x, default: 10' do
it "when x is set, it returns its value" do
expect(resource.x 20).to eq 20
- # expect(resource.property_is_set?(:x)).to be_truthy
+ expect(resource.property_is_set?(:x)).to be_truthy
expect(resource.x).to eq 20
end
it "when x is not set, it returns 10" do