]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/prefix_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / prefix_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the prefix function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "raises a ParseError if there is less than 1 arguments" do
8     expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/)
9   end
10
11   it "raises an error if the first argument is not an array" do
12     expect {
13       scope.function_prefix([Object.new])
14     }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/)
15   end
16
17
18   it "raises an error if the second argument is not a string" do
19     expect {
20       scope.function_prefix([['first', 'second'], 42])
21     }.to raise_error(Puppet::ParseError, /expected second argument to be a String/)
22   end
23
24   it "returns a prefixed array" do
25     result = scope.function_prefix([['a','b','c'], 'p'])
26     expect(result).to(eq(['pa','pb','pc']))
27   end
28
29   it "returns a prefixed hash" do
30     result = scope.function_prefix([{'a' => 'b','b' => 'c','c' => 'd'}, 'p'])
31     expect(result).to(eq({'pa'=>'b','pb'=>'c','pc'=>'d'}))
32   end
33 end