summaryrefslogtreecommitdiff
path: root/spec/unit/property_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/property_spec.rb')
-rw-r--r--spec/unit/property_spec.rb168
1 files changed, 84 insertions, 84 deletions
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 095dcc8e98..1fe8abc706 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -1,4 +1,4 @@
-require 'support/shared/integration/integration_helper'
+require "support/shared/integration/integration_helper"
describe "Chef::Resource.property" do
include IntegrationSupport
@@ -46,7 +46,7 @@ describe "Chef::Resource.property" do
end
def self.english_join(values)
- return '<nothing>' if values.size == 0
+ return "<nothing>" if values.size == 0
return values[0].inspect if values.size == 1
"#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
end
@@ -74,7 +74,7 @@ describe "Chef::Resource.property" do
end
# Basic properties
- with_property ':bare_property' do
+ with_property ":bare_property" do
it "can be set" do
expect(resource.bare_property 10).to eq 10
expect(resource.bare_property).to eq 10
@@ -116,7 +116,7 @@ describe "Chef::Resource.property" do
end
end
let(:subresource) do
- subresource_class.new('blah')
+ subresource_class.new("blah")
end
context "with property :x on the subclass" do
@@ -127,7 +127,7 @@ describe "Chef::Resource.property" do
end
it "x is still name_property" do
- expect(subresource.x).to eq 'blah'
+ expect(subresource.x).to eq "blah"
end
end
@@ -166,7 +166,7 @@ describe "Chef::Resource.property" do
end
end
let(:subresource) do
- subresource_class.new('blah')
+ subresource_class.new("blah")
end
it "x is inherited" do
@@ -178,7 +178,7 @@ describe "Chef::Resource.property" do
end
it "x's validation is inherited" do
- expect { subresource.x 'ohno' }.to raise_error Chef::Exceptions::ValidationFailed
+ expect { subresource.x "ohno" }.to raise_error Chef::Exceptions::ValidationFailed
end
context "with property :y on the subclass" do
@@ -225,7 +225,7 @@ describe "Chef::Resource.property" do
end
it "x's validation is inherited" do
- expect { subresource.x 'ohno' }.to raise_error Chef::Exceptions::ValidationFailed
+ expect { subresource.x "ohno" }.to raise_error Chef::Exceptions::ValidationFailed
end
end
@@ -250,7 +250,7 @@ describe "Chef::Resource.property" do
end
it "x's validation is inherited" do
- expect { subresource.x 'ohno' }.to raise_error Chef::Exceptions::ValidationFailed
+ expect { subresource.x "ohno" }.to raise_error Chef::Exceptions::ValidationFailed
end
end
@@ -272,12 +272,12 @@ describe "Chef::Resource.property" do
it "x's validation is overwritten" do
expect { subresource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
- expect(subresource.x 'ohno').to eq 'ohno'
- expect(subresource.x).to eq 'ohno'
+ expect(subresource.x "ohno").to eq "ohno"
+ expect(subresource.x).to eq "ohno"
end
it "the superclass's validation for x is still there" do
- expect { resource.x 'ohno' }.to raise_error Chef::Exceptions::ValidationFailed
+ expect { resource.x "ohno" }.to raise_error Chef::Exceptions::ValidationFailed
expect(resource.x 10).to eq 10
expect(resource.x).to eq 10
end
@@ -297,7 +297,7 @@ describe "Chef::Resource.property" do
expect { resource.reset_property(:x) }.to raise_error(ArgumentError)
end
- with_property ':x' do
+ with_property ":x" do
it "when the resource is newly created, reset_property(:x) does nothing" do
expect(resource.property_is_set?(:x)).to be_falsey
resource.reset_property(:x)
@@ -313,7 +313,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, Integer' do
+ with_property ":x, Integer" do
it "when the resource is newly created, reset_property(:x) does nothing" do
expect(resource.property_is_set?(:x)).to be_falsey
resource.reset_property(:x)
@@ -329,7 +329,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: 10' do
+ with_property ":x, default: 10" do
it "when the resource is newly created, reset_property(:x) does nothing" do
expect(resource.property_is_set?(:x)).to be_falsey
resource.reset_property(:x)
@@ -344,7 +344,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: lazy { 10 }' do
+ with_property ":x, default: lazy { 10 }" do
it "when the resource is newly created, reset_property(:x) does nothing" do
expect(resource.property_is_set?(:x)).to be_falsey
resource.reset_property(:x)
@@ -369,7 +369,7 @@ describe "Chef::Resource.property" do
expect { resource.property_is_set?(:x) }.to raise_error(ArgumentError)
end
- with_property ':x' do
+ 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
@@ -391,7 +391,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: 10' do
+ 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
@@ -413,7 +413,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: nil' do
+ 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
@@ -435,7 +435,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: lazy { 10 }' do
+ 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
@@ -455,7 +455,7 @@ describe "Chef::Resource.property" do
end
context "Chef::Resource::Property#default" do
- with_property ':x, default: 10' 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
@@ -479,33 +479,33 @@ describe "Chef::Resource.property" do
resource_name new_resource_name
end
end
- let(:subresource) { subresource_class.new('blah') }
+ let(:subresource) { subresource_class.new("blah") }
it "The default is inherited" do
expect(subresource.x).to eq 10
end
end
end
- with_property ':x, default: 10, identity: true' do
+ with_property ":x, default: 10, identity: true" do
it "when x is not set, it is included in identity" do
expect(resource.identity).to eq(10)
end
end
- with_property ':x, default: 1, identity: true', ':y, default: 2, identity: true' do
+ with_property ":x, default: 1, identity: true", ":y, default: 2, identity: true" do
it "when x is not set, it is still included in identity" do
resource.y 20
expect(resource.identity).to eq(x: 1, y: 20)
end
end
- with_property ':x, default: nil' do
+ with_property ":x, default: nil" do
it "when x is not set, it returns nil" do
expect(resource.x).to be_nil
end
end
- with_property ':x' do
+ with_property ":x" do
it "when x is not set, it returns nil" do
expect(resource.x).to be_nil
end
@@ -515,7 +515,7 @@ describe "Chef::Resource.property" do
context "(deprecations allowed)" do
before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
- with_property ':x, default: {}' do
+ with_property ":x, default: {}" do
it "when x is not set, it returns {}" do
expect(resource.x).to eq({})
end
@@ -525,12 +525,12 @@ describe "Chef::Resource.property" do
expect(resource.x.object_id).to eq(value.object_id)
end
it "Multiple instances of x receive the exact same value" do
- expect(resource.x.object_id).to eq(resource_class.new('blah2').x.object_id)
+ expect(resource.x.object_id).to eq(resource_class.new("blah2").x.object_id)
end
end
end
- with_property ':x, default: lazy { {} }' do
+ with_property ":x, default: lazy { {} }" do
it "when x is not set, it returns {}" do
expect(resource.x).to eq({})
end
@@ -540,7 +540,7 @@ describe "Chef::Resource.property" do
# expect(resource.x.object_id).not_to eq(value.object_id)
# end
it "Multiple instances of x receive different values" do
- expect(resource.x.object_id).not_to eq(resource_class.new('blah2').x.object_id)
+ expect(resource.x.object_id).not_to eq(resource_class.new("blah2").x.object_id)
end
end
end
@@ -549,7 +549,7 @@ describe "Chef::Resource.property" do
before do
resource_class.class_eval do
def self.blah
- 'class'
+ "class"
end
def blah
"#{name}#{next_index}"
@@ -557,13 +557,13 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, default: lazy { blah }' do
+ with_property ":x, default: lazy { blah }" do
it "x is run in context of the instance" do
expect(resource.x).to eq "blah1"
end
it "x is run in the context of each instance it is run in" do
expect(resource.x).to eq "blah1"
- expect(resource_class.new('another').x).to eq "another2"
+ expect(resource_class.new("another").x).to eq "another2"
# expect(resource.x).to eq "blah3"
end
end
@@ -574,20 +574,20 @@ describe "Chef::Resource.property" do
end
it "x is passed the value of each instance it is run in" do
expect(resource.x).to eq "classblah1"
- expect(resource_class.new('another').x).to eq "classanother2"
+ expect(resource_class.new("another").x).to eq "classanother2"
# expect(resource.x).to eq "classblah3"
end
end
end
context "validation of defaults" do
- with_property ':x, String, default: 10' do
+ with_property ":x, String, default: 10" do
it "when the resource is created, no error is raised" do
resource
end
it "when x is set, no error is raised" do
- expect(resource.x 'hi').to eq 'hi'
- expect(resource.x).to eq 'hi'
+ expect(resource.x "hi").to eq "hi"
+ expect(resource.x).to eq "hi"
end
it "when x is retrieved, no validation error is raised" do
expect(resource.x).to eq 10
@@ -602,8 +602,8 @@ describe "Chef::Resource.property" do
resource
end
it "when x is set, no error is raised" do
- expect(resource.x 'hi').to eq 'hi'
- expect(resource.x).to eq 'hi'
+ expect(resource.x "hi").to eq "hi"
+ expect(resource.x).to eq "hi"
end
it "when x is retrieved, no validation error is raised" do
expect(resource.x).to eq 1
@@ -617,7 +617,7 @@ describe "Chef::Resource.property" do
with_property ":x, default: lazy { Namer.next_index.to_s }, is: proc { |v| Namer.next_index; true }" do
it "validation is not run at all on the default value" do
- expect(resource.x).to eq '1'
+ expect(resource.x).to eq "1"
expect(Namer.current_index).to eq 1
end
# it "validation is run each time" do
@@ -630,7 +630,7 @@ describe "Chef::Resource.property" do
with_property ":x, default: lazy { Namer.next_index.to_s.freeze }, is: proc { |v| Namer.next_index; true }" do
it "validation is not run at all on the default value" do
- expect(resource.x).to eq '1'
+ expect(resource.x).to eq "1"
expect(Namer.current_index).to eq 1
end
# it "validation is only run the first time" do
@@ -650,13 +650,13 @@ describe "Chef::Resource.property" do
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(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 exactly once" do
- expect(resource.x).to eq '101'
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
end
end
@@ -668,13 +668,13 @@ describe "Chef::Resource.property" do
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(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(resource.x).to eq "101"
+ expect(resource.x).to eq "102"
expect(Namer.current_index).to eq 2
end
end
@@ -686,13 +686,13 @@ describe "Chef::Resource.property" do
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(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 exactly once" do
- expect(resource.x).to eq '101'
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
end
end
@@ -704,13 +704,13 @@ describe "Chef::Resource.property" do
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(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(resource.x).to eq "101"
+ expect(resource.x).to eq "102"
expect(Namer.current_index).to eq 2
end
end
@@ -718,9 +718,9 @@ describe "Chef::Resource.property" do
with_property ':x, proc { |v| Namer.next_index; true }, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do
it "coercion is only run the first time x is retrieved, and validation is not run" do
expect(Namer.current_index).to eq 0
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
end
end
@@ -728,12 +728,12 @@ describe "Chef::Resource.property" do
context "validation and coercion of defaults" do
with_property ':x, String, coerce: proc { |v| "#{v}#{next_index}" }, default: 10' do
it "when x is retrieved, it is coerced before validating and passes" do
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
end
end
with_property ':x, Integer, coerce: proc { |v| "#{v}#{next_index}" }, default: 10' do
it "when x is retrieved, it is coerced and not validated" do
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
end
# it "when x is retrieved, it is coerced before validating and fails" do
# expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
@@ -741,12 +741,12 @@ describe "Chef::Resource.property" do
end
with_property ':x, String, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do
it "when x is retrieved, it is coerced before validating and passes" do
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
end
end
with_property ':x, Integer, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do
it "when x is retrieved, it is coerced and not validated" do
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
end
# it "when x is retrieved, it is coerced before validating and fails" do
# expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
@@ -755,9 +755,9 @@ describe "Chef::Resource.property" do
with_property ':x, proc { |v| Namer.next_index; true }, coerce: proc { |v| "#{v}#{next_index}" }, default: lazy { 10 }' do
it "coercion is only run the first time x is retrieved, and validation is not run" do
expect(Namer.current_index).to eq 0
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
- expect(resource.x).to eq '101'
+ expect(resource.x).to eq "101"
expect(Namer.current_index).to eq 1
end
end
@@ -766,7 +766,7 @@ describe "Chef::Resource.property" do
end
context "Chef::Resource#lazy" do
- with_property ':x' do
+ with_property ":x" do
it "setting x to a lazy value does not run it immediately" do
resource.x lazy { Namer.next_index }
expect(Namer.current_index).to eq 0
@@ -861,7 +861,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, String' do
+ with_property ":x, String" do
it "lazy values are not validated on set" do
resource.x lazy { Namer.next_index }
expect(Namer.current_index).to eq 0
@@ -873,7 +873,7 @@ describe "Chef::Resource.property" do
end
end
- with_property ':x, is: proc { |v| Namer.next_index; true }' do
+ with_property ":x, is: proc { |v| Namer.next_index; true }" do
it "lazy values are validated on each access" do
resource.x lazy { Namer.next_index }
expect(resource.x).to eq 1
@@ -936,7 +936,7 @@ describe "Chef::Resource.property" do
expect(Namer.current_index).to eq 2
end
end
- with_property ':x, coerce: proc { |x| x }' do
+ with_property ":x, coerce: proc { |x| x }" do
it "does not emit a deprecation warning if set to nil" do
expect(resource.x nil).to be_nil
end
@@ -946,19 +946,19 @@ describe "Chef::Resource.property" do
resource.x 20
expect(resource.x).to eq 20
expect(Namer.current_index).to eq 2
- expect { resource.x 10 }.to raise_error 'hi'
+ expect { resource.x 10 }.to raise_error "hi"
expect(resource.x).to eq 20
expect(Namer.current_index).to eq 3
end
it "validation does not run if coercion fails" do
- expect { resource.x 10 }.to raise_error 'hi'
+ expect { resource.x 10 }.to raise_error "hi"
expect(Namer.current_index).to eq 1
end
end
end
context "Chef::Resource::Property validation" do
- with_property ':x, is: proc { |v| Namer.next_index; v.is_a?(Integer) }' do
+ with_property ":x, is: proc { |v| Namer.next_index; v.is_a?(Integer) }" do
it "validation runs on set" do
expect(resource.x 10).to eq 10
expect(Namer.current_index).to eq 1
@@ -977,31 +977,31 @@ describe "Chef::Resource.property" do
it "failed validation fails to set the value" do
expect(resource.x 10).to eq 10
expect(Namer.current_index).to eq 1
- expect { resource.x 'blah' }.to raise_error Chef::Exceptions::ValidationFailed
+ expect { resource.x "blah" }.to raise_error Chef::Exceptions::ValidationFailed
expect(resource.x).to eq 10
expect(Namer.current_index).to eq 2
end
end
end
- [ 'name_attribute', 'name_property' ].each do |name|
+ [ "name_attribute", "name_property" ].each do |name|
context "Chef::Resource::Property##{name}" do
with_property ":x, #{name}: true" do
it "defaults x to resource.name" do
- expect(resource.x).to eq 'blah'
+ expect(resource.x).to eq "blah"
end
it "does not pick up resource.name if set" do
expect(resource.x 10).to eq 10
expect(resource.x).to eq 10
end
it "binds to the latest resource.name when run" do
- resource.name 'foo'
- expect(resource.x).to eq 'foo'
+ resource.name "foo"
+ expect(resource.x).to eq "foo"
end
it "caches resource.name" do
- expect(resource.x).to eq 'blah'
- resource.name 'foo'
- expect(resource.x).to eq 'blah'
+ expect(resource.x).to eq "blah"
+ resource.name "foo"
+ expect(resource.x).to eq "blah"
end
end
@@ -1045,17 +1045,17 @@ describe "Chef::Resource.property" do
end
with_property ":x, default: nil, #{name}: true" do
it "chooses #{name} over default" do
- expect(resource.x).to eq 'blah'
+ expect(resource.x).to eq "blah"
end
end
with_property ":x, #{name}: true, default: 10" do
it "chooses #{name} over default" do
- expect(resource.x).to eq 'blah'
+ expect(resource.x).to eq "blah"
end
end
with_property ":x, #{name}: true, default: nil" do
it "chooses #{name} over default" do
- expect(resource.x).to eq 'blah'
+ expect(resource.x).to eq "blah"
end
end
end
@@ -1117,7 +1117,7 @@ describe "Chef::Resource.property" do
end
end
let(:subresource) do
- subresource_class.new('blah')
+ subresource_class.new("blah")
end
context "with property :x, default: 10 on the subclass" do