]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/join_keys_to_values_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / join_keys_to_values_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the join_keys_to_values function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("function_join_keys_to_values")
9   end
10
11   it "should raise a ParseError if there are fewer than two arguments" do
12     expect { scope.function_join_keys_to_values([{}]) }.to raise_error Puppet::ParseError
13   end
14
15   it "should raise a ParseError if there are greater than two arguments" do
16     expect { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.to raise_error Puppet::ParseError
17   end
18
19   it "should raise a TypeError if the first argument is an array" do
20     expect { scope.function_join_keys_to_values([[1,2], ',']) }.to raise_error TypeError
21   end
22
23   it "should raise a TypeError if the second argument is an array" do
24     expect { scope.function_join_keys_to_values([{}, [1,2]]) }.to raise_error TypeError
25   end
26
27   it "should raise a TypeError if the second argument is a number" do
28     expect { scope.function_join_keys_to_values([{}, 1]) }.to raise_error TypeError
29   end
30
31   it "should return an empty array given an empty hash" do
32     result = scope.function_join_keys_to_values([{}, ":"])
33     expect(result).to eq([])
34   end
35
36   it "should join hash's keys to its values" do
37     result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
38     expect(result).to match_array(['a:1','2:foo','b:'])
39   end
40 end