summaryrefslogtreecommitdiff
path: root/spec/unit/mixin
diff options
context:
space:
mode:
authorChris Roberts <chrisroberts.code@gmail.com>2013-01-10 16:29:14 -0800
committerdanielsdeleo <dan@opscode.com>2013-06-19 09:10:21 -0700
commitbbc54a11e03a6b49ef91f58725a84a2e7693ada7 (patch)
tree052c0b42821670e222bbdfefed1c2ac5783b2432 /spec/unit/mixin
parent0499d32925784ad83d8950c64be560ac743fa32d (diff)
downloadchef-bbc54a11e03a6b49ef91f58725a84a2e7693ada7.tar.gz
More specs for more coverage on delayed evaluator usage
Diffstat (limited to 'spec/unit/mixin')
-rw-r--r--spec/unit/mixin/params_validate_spec.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb
index 7c70dd1ca9..8fca6a936e 100644
--- a/spec/unit/mixin/params_validate_spec.rb
+++ b/spec/unit/mixin/params_validate_spec.rb
@@ -369,13 +369,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
@@ -383,6 +382,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, {})