summaryrefslogtreecommitdiff
path: root/spec/unit/property_spec.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-30 13:58:09 -0600
committerJohn Keiser <john@johnkeiser.com>2015-07-03 13:10:23 -0600
commit88e90f48952d0776b2d2b5f641c3d1b08c1376bb (patch)
treef9b3027cd6ce01a38e937805d642a58ce16d8dd9 /spec/unit/property_spec.rb
parentd08645c68967630030bc70934899e092744487d1 (diff)
downloadchef-88e90f48952d0776b2d2b5f641c3d1b08c1376bb.tar.gz
Only stick non-frozen values to the resource
Diffstat (limited to 'spec/unit/property_spec.rb')
-rw-r--r--spec/unit/property_spec.rb47
1 files changed, 45 insertions, 2 deletions
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index c613739522..23f6f51d2c 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -397,9 +397,9 @@ describe "Chef::Resource.property" 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
+ it "when x is retrieved, property_is_set?(:x) is false" do
resource.x
- expect(resource.property_is_set?(:x)).to be_truthy
+ expect(resource.property_is_set?(:x)).to be_falsey
end
end
end
@@ -595,6 +595,7 @@ describe "Chef::Resource.property" do
end
context "coercion of defaults" do
+ # Frozen default, non-frozen coerce
with_property ':x, coerce: proc { |v| "#{v}#{next_index}" }, default: 10' do
it "when the resource is created, the proc is not yet run" do
resource
@@ -605,6 +606,24 @@ describe "Chef::Resource.property" do
expect(resource.x).to eq 'hi1'
expect(Namer.current_index).to eq 1
end
+ it "when x is retrieved, coercion is run exactly once" do
+ expect(resource.x).to eq '101'
+ expect(resource.x).to eq '101'
+ expect(Namer.current_index).to eq 1
+ end
+ end
+
+ # Frozen default, frozen coerce
+ with_property ':x, coerce: proc { |v| "#{v}#{next_index}".freeze }, default: 10' do
+ it "when the resource is created, the proc is not yet run" do
+ resource
+ expect(Namer.current_index).to eq 0
+ end
+ it "when x is set, coercion is run" do
+ expect(resource.x 'hi').to eq 'hi1'
+ expect(resource.x).to eq 'hi1'
+ expect(Namer.current_index).to eq 1
+ end
it "when x is retrieved, coercion is run each time" do
expect(resource.x).to eq '101'
expect(resource.x).to eq '102'
@@ -612,6 +631,7 @@ describe "Chef::Resource.property" do
end
end
+ # Frozen lazy default, non-frozen coerce
with_property ':x, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do
it "when the resource is created, the proc is not yet run" do
resource
@@ -622,6 +642,29 @@ describe "Chef::Resource.property" do
expect(resource.x).to eq 'hi1'
expect(Namer.current_index).to eq 1
end
+ it "when x is retrieved, coercion is run exactly once" do
+ expect(resource.x).to eq '101'
+ expect(resource.x).to eq '101'
+ expect(Namer.current_index).to eq 1
+ end
+ end
+
+ # Non-frozen lazy default, frozen coerce
+ with_property ':x, coerce: proc { |v| "#{v}#{next_index}".freeze }, default: lazy { "10" }' do
+ it "when the resource is created, the proc is not yet run" do
+ resource
+ expect(Namer.current_index).to eq 0
+ end
+ it "when x is set, coercion is run" do
+ expect(resource.x 'hi').to eq 'hi1'
+ expect(resource.x).to eq 'hi1'
+ expect(Namer.current_index).to eq 1
+ end
+ it "when x is retrieved, coercion is run each time" do
+ expect(resource.x).to eq '101'
+ expect(resource.x).to eq '102'
+ expect(Namer.current_index).to eq 2
+ end
end
with_property ':x, proc { |v| Namer.next_index; true }, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do