summaryrefslogtreecommitdiff
path: root/spec/unit/mixin
diff options
context:
space:
mode:
authorChris Roberts <chrisroberts.code@gmail.com>2012-12-27 09:16:44 -0800
committerdanielsdeleo <dan@opscode.com>2013-06-19 09:10:20 -0700
commit0499d32925784ad83d8950c64be560ac743fa32d (patch)
tree0cbe928c4a213dfe5e535b08f3896f267b648b17 /spec/unit/mixin
parent55fcbe532a14fe1458f469cb932fbe6059e758cc (diff)
downloadchef-0499d32925784ad83d8950c64be560ac743fa32d.tar.gz
Allow delayed attribute evaluation. Add tests for delayed evaluation
Conflicts: lib/chef/mixin/params_validate.rb
Diffstat (limited to 'spec/unit/mixin')
-rw-r--r--spec/unit/mixin/params_validate_spec.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb
index b79156109b..7c70dd1ca9 100644
--- a/spec/unit/mixin/params_validate_spec.rb
+++ b/spec/unit/mixin/params_validate_spec.rb
@@ -368,5 +368,26 @@ describe Chef::Mixin::ParamsValidate do
@vo.set_or_return(:name, value, { }).object_id.should == value.object_id
@vo.set_or_return(:foo, nil, { :name_attribute => true }).object_id.should == value.object_id
end
+
+ it "should allow DynamicEvaluator instance to be set for value regardless of restriction" do
+ value = Chef::DelayedEvaluator.new{ 'test' }
+ @vo.set_or_return(:test, value, {:kind_of => String})
+ @vo.set_or_return(:test, nil, {:kind_of => String}).should == 'test'
+ end
+
+ it "should raise an error when evaluated attribute is not valid" do
+ value = Chef::DelayedEvaluator.new{ 'test' }
+ @vo.set_or_return(:test, value, {:kind_of => Numeric})
+ lambda do
+ @vo.set_or_return(:test, nil, {:kind_of => Numeric})
+ end.should raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "should not evaluate non DelayedEvaluator instances" do
+ value = lambda{ 'test' }
+ @vo.set_or_return(:test, value, {})
+ @vo.set_or_return(:test, nil, {}).object_id.should == value.object_id
+ @vo.set_or_return(:test, nil, {}).should be_a(Proc)
+ end
end