summaryrefslogtreecommitdiff
path: root/spec/unit/parser/functions/inline_template_spec.rb
blob: ed0911e4240754e9e6e0dc0780923dcaf7af9e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env ruby
require 'spec_helper'

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

  let(:node) { Puppet::Node.new('localhost') }
  let(:compiler) { Puppet::Parser::Compiler.new(node) }
  let(:scope) { Puppet::Parser::Scope.new(compiler) }

  it "should concatenate template wrapper outputs for multiple templates" do
    inline_template("template1", "template2").should == "template1template2"
  end

  it "should raise an error if the template raises an error" do
    expect { inline_template("<% raise 'error' %>") }.to raise_error(Puppet::ParseError)
  end

  it "is not interfered with by a variable called 'string' (#14093)" do
    scope['string'] = "this is a variable"
    inline_template("this is a template").should == "this is a template"
  end

  it "has access to a variable called 'string' (#14093)" do
    scope['string'] = "this is a variable"
    inline_template("string was: <%= @string %>").should == "string was: this is a variable"
  end

  def inline_template(*templates)
    scope.function_inline_template(templates)
  end
end