Sha256: 41083d6c3f7558ce83784832a17b83af5f975520a9a868ae02a67ed46491d751

Contents?: true

Size: 1.91 KB

Versions: 12

Compression:

Stored size: 1.91 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

describe "the inline_template function" do
  before :all do
    Puppet::Parser::Functions.autoloader.loadall
  end

  before :each do
    node     = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    @scope   = Puppet::Parser::Scope.new(compiler)
  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

12 entries across 12 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/unit/parser/functions/inline_template_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/unit/parser/functions/inline_template_spec.rb
puppet-3.1.0 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.1.0.rc2 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.1.0.rc1 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.2 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.2.rc3 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.2.rc2 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.2.rc1 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.1 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.1.rc1 spec/unit/parser/functions/inline_template_spec.rb
puppet-3.0.0 spec/unit/parser/functions/inline_template_spec.rb