|
| 1 | +#! /usr/bin/env ruby -S rspec |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe "the basename function" do |
| 5 | + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } |
| 6 | + |
| 7 | + it "should exist" do |
| 8 | + Puppet::Parser::Functions.function("basename").should == "function_basename" |
| 9 | + end |
| 10 | + |
| 11 | + it "should raise a ParseError if there is less than 1 argument" do |
| 12 | + lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) |
| 13 | + end |
| 14 | + |
| 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)) |
| 17 | + end |
| 18 | + |
| 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')) |
| 22 | + end |
| 23 | + |
| 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')) |
| 27 | + end |
| 28 | + |
| 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')) |
| 32 | + end |
| 33 | + |
| 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')) |
| 37 | + end |
| 38 | + |
| 39 | + it "should complain about non-string first argument" do |
| 40 | + lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) |
| 41 | + end |
| 42 | + |
| 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)) |
| 45 | + end |
| 46 | +end |
0 commit comments