Sha256: a9753d4a84480ddcc8e8db035b532e46183c5136f891978c2cd8662da40c3183

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

#! /usr/bin/env ruby -S rspec
require 'spec_helper'

describe "the basename function" do
  let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

  it "should exist" do
    Puppet::Parser::Functions.function("basename").should == "function_basename"
  end

  it "should raise a ParseError if there is less than 1 argument" do
    lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError))
  end

  it "should raise a ParseError if there are more than 2 arguments" do
    lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError))
  end

  it "should return basename for an absolute path" do
    result = scope.function_basename(['/path/to/a/file.ext'])
    result.should(eq('file.ext'))
  end

  it "should return basename for a relative path" do
    result = scope.function_basename(['path/to/a/file.ext'])
    result.should(eq('file.ext'))
  end

  it "should strip extention when extension specified (absolute path)" do
    result = scope.function_basename(['/path/to/a/file.ext', '.ext'])
    result.should(eq('file'))
  end

  it "should strip extention when extension specified (relative path)" do
    result = scope.function_basename(['path/to/a/file.ext', '.ext'])
    result.should(eq('file'))
  end

  it "should complain about non-string first argument" do
    lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError))
  end

  it "should complain about non-string second argument" do
    lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError))
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-retrospec-0.12.1 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb
puppet-retrospec-0.12.0 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb
puppet-retrospec-0.11.0 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb
puppet-retrospec-0.10.0 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb
puppet-retrospec-0.9.1 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb
puppet-retrospec-0.9.0 spec/fixtures/modules/stdlib/spec/unit/puppet/parser/functions/basename_spec.rb