1 #! /usr/bin/env ruby -S rspec
4 describe "the basename function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 Puppet::Parser::Functions.function("basename").should == "function_basename"
11 it "should raise a ParseError if there is less than 1 argument" do
12 lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError))
15 it "should raise a ParseError if there are more than 2 arguments" do
16 lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError))
19 it "should return basename for an absolute path" do
20 result = scope.function_basename(['/path/to/a/file.ext'])
21 result.should(eq('file.ext'))
24 it "should return basename for a relative path" do
25 result = scope.function_basename(['path/to/a/file.ext'])
26 result.should(eq('file.ext'))
29 it "should strip extention when extension specified (absolute path)" do
30 result = scope.function_basename(['/path/to/a/file.ext', '.ext'])
31 result.should(eq('file'))
34 it "should strip extention when extension specified (relative path)" do
35 result = scope.function_basename(['path/to/a/file.ext', '.ext'])
36 result.should(eq('file'))
39 it "should complain about non-string first argument" do
40 lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError))
43 it "should complain about non-string second argument" do
44 lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError))