1 #! /usr/bin/env ruby -S rspec
4 describe "the dirname function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("dirname")).to eq("function_dirname")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_dirname([]) }.to( raise_error(Puppet::ParseError))
15 it "should raise a ParseError if there is more than 1 argument" do
16 expect { scope.function_dirname(['a', 'b']) }.to( raise_error(Puppet::ParseError))
19 it "should return dirname for an absolute path" do
20 result = scope.function_dirname(['/path/to/a/file.ext'])
21 expect(result).to(eq('/path/to/a'))
24 it "should return dirname for a relative path" do
25 result = scope.function_dirname(['path/to/a/file.ext'])
26 expect(result).to(eq('path/to/a'))
29 it "should complain about hash argument" do
30 expect { scope.function_dirname([{}]) }.to( raise_error(Puppet::ParseError))
32 it "should complain about list argument" do
33 expect { scope.function_dirname([[]]) }.to( raise_error(Puppet::ParseError))
35 it "should complain about numeric argument" do
36 expect { scope.function_dirname([2112]) }.to( raise_error(Puppet::ParseError))