summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Roberts <chrisroberts.code@gmail.com>2013-01-10 16:29:14 -0800
committerBryan McLellan <btm@opscode.com>2013-05-24 11:18:29 -0700
commit8dba088b14686588d08031f9be3998eac205751e (patch)
tree3ddafd0a9284cfc0af4c6f61f98a2b0bef48d424
parentdb616869b7ace2cd853370685d025e6ac62d3cb1 (diff)
downloadchef-8dba088b14686588d08031f9be3998eac205751e.tar.gz
More specs for more coverage on delayed evaluator usage
-rw-r--r--chef/spec/unit/mixin/params_validate_spec.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/chef/spec/unit/mixin/params_validate_spec.rb b/chef/spec/unit/mixin/params_validate_spec.rb
index 25c0c17f1e..414d1ef622 100644
--- a/chef/spec/unit/mixin/params_validate_spec.rb
+++ b/chef/spec/unit/mixin/params_validate_spec.rb
@@ -367,13 +367,12 @@ describe Chef::Mixin::ParamsValidate do
@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
+ it "should allow DelayedEvaluator 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'
+ @vo.set_or_return(:test, value, {:kind_of => Numeric})
end
- it "should raise an error when evaluated attribute is not valid" do
+ it "should raise an error when delayed evaluated attribute is not valid" do
value = Chef::DelayedEvaluator.new{ 'test' }
@vo.set_or_return(:test, value, {:kind_of => Numeric})
lambda do
@@ -381,6 +380,25 @@ describe Chef::Mixin::ParamsValidate do
end.should raise_error(Chef::Exceptions::ValidationFailed)
end
+ it "should create DelayedEvaluator instance when passed a block" do
+ @vo.set_or_return(:delayed, nil, {}) do
+ 'test'
+ end
+ @vo.instance_variable_get(:@delayed).should be_a(Chef::DelayedEvaluator)
+ end
+
+ it "should execute block on each call when DelayedEvaluator" do
+ value = 'fubar'
+ @vo.set_or_return(:test, nil, {}) do
+ value
+ end
+ @vo.set_or_return(:test, nil, {}).should == 'fubar'
+ value = 'foobar'
+ @vo.set_or_return(:test, nil, {}).should == 'foobar'
+ value = 'fauxbar'
+ @vo.set_or_return(:test, nil, {}).should == 'fauxbar'
+ end
+
it "should not evaluate non DelayedEvaluator instances" do
value = lambda{ 'test' }
@vo.set_or_return(:test, value, {})