summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions/template.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-11-23 00:01:04 +0100
committerBrice Figureau <brice-puppet@daysofwonder.com>2008-11-29 12:00:21 +0100
commitcc45c435b7f62f83f0d0cd4b952a5c05ccfaaac9 (patch)
treeec2cf2e1c5f7327230f3c0372119e6c7b71b0298 /spec/unit/parser/functions/template.rb
parentd8c741f9d3b07b11f11af0765d740d9e78889794 (diff)
downloadpuppet-cc45c435b7f62f83f0d0cd4b952a5c05ccfaaac9.tar.gz
puppet-cc45c435b7f62f83f0d0cd4b952a5c05ccfaaac9.tar.xz
puppet-cc45c435b7f62f83f0d0cd4b952a5c05ccfaaac9.zip
Fix #1741 - refactor TemplateWrapper, test for template function
Diffstat (limited to 'spec/unit/parser/functions/template.rb')
-rw-r--r--spec/unit/parser/functions/template.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/template.rb b/spec/unit/parser/functions/template.rb
new file mode 100644
index 000000000..8fc64d0c3
--- /dev/null
+++ b/spec/unit/parser/functions/template.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the template function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("template").should == "function_template"
+ end
+
+ it "should create a TemplateWrapper when called" do
+ tw = stub_everything 'template_wrapper'
+
+ Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
+
+ @scope.function_template("test")
+ end
+
+ it "should give the template filename to the TemplateWrapper" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+
+ tw.expects(:file=).with("test")
+
+ @scope.function_template("test")
+ end
+
+ it "should return what TemplateWrapper.result returns" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ tw.stubs(:file=).with("test")
+
+ tw.expects(:result).returns("template contents evaluated")
+
+ @scope.function_template("test").should == "template contents evaluated"
+ end
+
+ it "should concatenate template wrapper outputs for multiple templates" do
+ tw1 = stub_everything "template_wrapper1"
+ tw2 = stub_everything "template_wrapper2"
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
+ tw1.stubs(:file=).with("1")
+ tw2.stubs(:file=).with("2")
+ tw1.stubs(:result).returns("result1")
+ tw2.stubs(:result).returns("result2")
+
+ @scope.function_template(["1","2"]).should == "result1result2"
+ end
+
+ it "should raise an error if the template raises an error" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ tw.stubs(:result).raises
+
+ lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
+ end
+
+end \ No newline at end of file