summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/templatewrapper_spec.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-21 17:24:09 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 12:47:31 -0700
commit31f8e660c8f4c0ec01f140322cf7c585144a0888 (patch)
tree115f2b3d2b31c005b4b0de81b74d9195fa6ca495 /spec/unit/parser/templatewrapper_spec.rb
parentd5dc3036eda210f318160e2442f7b65e0995ee23 (diff)
downloadpuppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.tar.gz
puppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.tar.xz
puppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.zip
Refactor en route to #5027 -- remove usestring parameter from lookupvar
The usestring parameter to lookupvar was objectionable for several reasons; first, it performed a function orthogonal to the main purpose of the method, second its default was the least common value, and third it was causing other code to work for reasons that were not obvious (extlookup). This refactor breaks the value-transforming function out into a seperate method which allows the user to specify the value to be used in lieu of :undef and removes the parameter. The function, Scope#undef_as(default,exp) is written so that it can be used in user code (templates, functions, etc.) if needed. This refactor will introduce a user-visible behaviour change in the case where users were counting on lookupvar to return "" for undefined variables. The best solution is to have them use undef_as, replacing: lookupvar('myvar') with undef_as('',lookupvar('myvar')) (with the option to specify another default value if desired). If this is too objectionable, we could rename the existing lookupvar as raw_lookupvar and define def lookupvar(v) undef_as('',raw_lookupvar(v)) end to restore the present behaviour.
Diffstat (limited to 'spec/unit/parser/templatewrapper_spec.rb')
-rwxr-xr-xspec/unit/parser/templatewrapper_spec.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb
index afb0032fd..4a713b8a8 100755
--- a/spec/unit/parser/templatewrapper_spec.rb
+++ b/spec/unit/parser/templatewrapper_spec.rb
@@ -70,25 +70,25 @@ describe Puppet::Parser::TemplateWrapper do
end
it "should return the contents of a variable if called via method_missing" do
- @scope.expects(:lookupvar).with("chicken", false).returns("is good")
+ @scope.expects(:lookupvar).with("chicken").returns("is good")
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.chicken.should eql("is good")
end
it "should throw an exception if a variable is called via method_missing and it does not exist" do
- @scope.expects(:lookupvar).with("chicken", false).returns(:undefined)
+ @scope.expects(:lookupvar).with("chicken").returns(:undefined)
tw = Puppet::Parser::TemplateWrapper.new(@scope)
lambda { tw.chicken }.should raise_error(Puppet::ParseError)
end
it "should allow you to check whether a variable is defined with has_variable?" do
- @scope.expects(:lookupvar).with("chicken", false).returns("is good")
+ @scope.expects(:lookupvar).with("chicken").returns("is good")
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.has_variable?("chicken").should eql(true)
end
it "should allow you to check whether a variable is not defined with has_variable?" do
- @scope.expects(:lookupvar).with("chicken", false).returns(:undefined)
+ @scope.expects(:lookupvar).with("chicken").returns(:undefined)
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.has_variable?("chicken").should eql(false)
end