1 #! /usr/bin/env ruby -S rspec
4 describe "the zip function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 it "should raise a ParseError if there is less than 1 arguments" do
8 expect { scope.function_zip([]) }.to( raise_error(Puppet::ParseError))
11 it "should be able to zip an array" do
12 result = scope.function_zip([['1','2','3'],['4','5','6']])
13 expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
14 result = scope.function_zip([['1','2','3'],['4','5','6'], false])
15 result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
18 it "should be able to zip an array and flatten" do
19 result = scope.function_zip([['1','2','3'],['4','5','6'], true])
20 result.should(eq(["1", "4", "2", "5", "3", "6"]))
23 it "should accept objects which extend String for the second argument" do
24 class AlsoString < String
27 value = AlsoString.new('false')
28 result = scope.function_zip([['1','2','3'],['4','5','6'],value])
29 result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))