Sha256: 8121796138dabb1d3b6067fda06a1029c9223277aca6abf78425868482c02fdd

Contents?: true

Size: 1.41 KB

Versions: 53

Compression:

Stored size: 1.41 KB

Contents

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

describe "the 'file' function" do
  include PuppetSpec::Files

  before :all do
    Puppet::Parser::Functions.autoloader.loadall
  end

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

  it "should exist" do
    Puppet::Parser::Functions.function("file").should == "function_file"
  end

  def with_file_content(content)
    path = tmpfile('file-function')
    file = File.new(path, 'w')
    file.sync = true
    file.print content
    yield path
  end

  it "should read a file" do
    with_file_content('file content') do |name|
      scope.function_file([name]).should == "file content"
    end
  end

  it "should return the first file if given two files" do
    with_file_content('one') do |one|
      with_file_content('two') do |two|
        scope.function_file([one, two]).should == "one"
      end
    end
  end

  it "should not fail when some files are absent" do
    expect {
      with_file_content('one') do |one|
        scope.function_file([make_absolute("/should-not-exist"), one]).should == 'one'
      end
    }.to_not raise_error
  end

  it "should fail when all files are absent" do
    expect {
      scope.function_file([File.expand_path('one')])
    }.to raise_error(Puppet::ParseError, /Could not find any files/)
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
puppet-3.6.2 spec/unit/parser/functions/file_spec.rb
puppet-3.6.2-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.6.1 spec/unit/parser/functions/file_spec.rb
puppet-3.6.1-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.6.0 spec/unit/parser/functions/file_spec.rb
puppet-3.6.0-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.6.0.rc1 spec/unit/parser/functions/file_spec.rb
puppet-3.6.0.rc1-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.5.1 spec/unit/parser/functions/file_spec.rb
puppet-3.5.1-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.5.1.rc1 spec/unit/parser/functions/file_spec.rb
puppet-3.5.1.rc1-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc3 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc3-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc2 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc2-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc1 spec/unit/parser/functions/file_spec.rb
puppet-3.5.0.rc1-x86-mingw32 spec/unit/parser/functions/file_spec.rb
puppet-3.4.3 spec/unit/parser/functions/file_spec.rb
puppet-3.4.2 spec/unit/parser/functions/file_spec.rb