Sha256: e7eb0038aa07792d862d3255340181b96dd9a3cef769fc123b8044ed00b3464a

Contents?: true

Size: 1.76 KB

Versions: 18

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe "the inline_template function" do

  before :each do
    @scope = Puppet::Parser::Scope.new
  end

  it "should exist" do
    Puppet::Parser::Functions.function("inline_template").should == "function_inline_template"
  end

  it "should create a TemplateWrapper when called" do
    tw = stub_everything 'template_wrapper'

    Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)

    @scope.function_inline_template("test")
  end

  it "should pass the template string to TemplateWrapper.result" do
    tw = stub_everything 'template_wrapper'
    Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)

    tw.expects(:result).with("test")

    @scope.function_inline_template("test")
  end

  it "should return what TemplateWrapper.result returns" do
    tw = stub_everything 'template_wrapper'
    Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)

    tw.expects(:result).returns("template contents evaluated")

    @scope.function_inline_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(:result).returns("result1")
    tw2.stubs(:result).returns("result2")

    @scope.function_inline_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_inline_template("1") }.should raise_error(Puppet::ParseError)
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
puppet-2.6.17 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.16 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.15 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.14 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.13 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.12 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.11 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.10 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.9 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.8 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.7 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.6 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.5 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.4 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.3 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.2 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.1 spec/unit/parser/functions/inline_template_spec.rb
puppet-2.6.0 spec/unit/parser/functions/inline_template_spec.rb