[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
James Turnbull
james at lovedthanlost.net
Fri Jan 23 14:20:47 UTC 2009
The following commit has been merged in the master branch:
commit 8a0cb16abd4c6a9cbf27d88593aa2b42a7375b94
Author: Luke Kanies <luke at madstop.com>
Date: Thu Aug 7 18:53:02 2008 -0700
Added tests for TemplateWrapper's use of Scope#to_hash.
We should deprecate the method_missing stuff in 0.25.
Signed-off-by: Luke Kanies <luke at madstop.com>
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 298428f..3b74e62 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -18,15 +18,6 @@ class Puppet::Parser::TemplateWrapper
if scope.parser
scope.parser.watch_file(file)
end
-
- # Expose all the variables in our scope as instance variables of the
- # current object, making it possible to access them without conflict
- # to the regular methods.
- benchmark(:debug, "Bound template variables for #{file}") do
- scope.to_hash.each { |name, value|
- instance_variable_set("@#{name}", value)
- }
- end
end
def scope
@@ -67,12 +58,20 @@ class Puppet::Parser::TemplateWrapper
else
# Just throw an error immediately, instead of searching for
# other missingmethod things or whatever.
- raise Puppet::ParseError,
- "Could not find value for '%s'" % name
+ raise Puppet::ParseError, "Could not find value for '%s'" % name
end
end
def result
+ # Expose all the variables in our scope as instance variables of the
+ # current object, making it possible to access them without conflict
+ # to the regular methods.
+ benchmark(:debug, "Bound template variables for #{file}") do
+ scope.to_hash.each { |name, value|
+ instance_variable_set("@#{name}", value)
+ }
+ end
+
result = nil
benchmark(:debug, "Interpolated template #{file}") do
template = ERB.new(File.read(file), 0, "-")
diff --git a/spec/unit/parser/templatewrapper.rb b/spec/unit/parser/templatewrapper.rb
index 40465f9..2d4bd14 100755
--- a/spec/unit/parser/templatewrapper.rb
+++ b/spec/unit/parser/templatewrapper.rb
@@ -6,7 +6,7 @@ describe Puppet::Parser::TemplateWrapper do
before(:each) do
compiler = stub('compiler', :environment => "foo")
parser = stub('parser', :watch_file => true)
- @scope = stub('scope', :compiler => compiler, :parser => parser)
+ @scope = stub('scope', :compiler => compiler, :parser => parser, :to_hash => {})
@file = "fake_template"
Puppet::Module.stubs(:find_template).returns("/tmp/fake_template")
FileTest.stubs(:exists?).returns("true")
@@ -54,4 +54,15 @@ describe Puppet::Parser::TemplateWrapper do
tw = Puppet::Parser::TemplateWrapper.new(@scope, @file)
tw.has_variable?("chicken").should eql(false)
end
+
+ it "should set all of the scope's variables as instance variables" do
+ template_mock = mock("template", :result => "woot!")
+ File.expects(:read).with("/tmp/fake_template").returns("template contents")
+ ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
+
+ @scope.expects(:to_hash).returns("one" => "foo")
+ @tw.result
+
+ @tw.instance_variable_get("@one").should == "foo"
+ end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list