1 #! /usr/bin/env ruby -S rspec
4 describe "the concat function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 it "should raise a ParseError if the client does not provide at least two arguments" do
8 expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
9 expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError))
12 it "should raise a ParseError if the first parameter is not an array" do
13 expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
16 it "should not raise a ParseError if the client provides more than two arguments" do
17 expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error
20 it "should be able to concat an array" do
21 result = scope.function_concat([['1','2','3'],['4','5','6']])
22 expect(result).to(eq(['1','2','3','4','5','6']))
25 it "should be able to concat a primitive to an array" do
26 result = scope.function_concat([['1','2','3'],'4'])
27 expect(result).to(eq(['1','2','3','4']))
30 it "should not accidentally flatten nested arrays" do
31 result = scope.function_concat([['1','2','3'],[['4','5'],'6']])
32 expect(result).to(eq(['1','2','3',['4','5'],'6']))
35 it "should leave the original array intact" do
36 array_original = ['1','2','3']
37 result = scope.function_concat([array_original,['4','5','6']])
38 array_original.should(eq(['1','2','3']))
41 it "should be able to concat multiple arrays" do
42 result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']])
43 expect(result).to(eq(['1','2','3','4','5','6','7','8','9']))
46 it "should be able to concat mix of primitives and arrays to a final array" do
47 result = scope.function_concat([['1','2','3'],'4',['5','6','7']])
48 expect(result).to(eq(['1','2','3','4','5','6','7']))