puppetlabs-stdlib/spec/acceptance/concat_spec.rb
Alex Tomlins 44596e73da (MODULES-3246) Fix concat with Hash arguments.
85d5ead Updated the concat function so that it wouldn't modify the
original array. A side-effect of this change is that it now always calls
`Array()` on the second argument. If thit is a Hash, this results in
`to_a` being called on the hash, which converts it to an array or
tuples. This is undesired.

Update the behaviour so that it doesn't (indirectly) call `to_a` on
anything, instead test for the type of the argument, wrapping it in an
array if it's not already an array.
2016-04-08 13:42:13 +01:00

54 lines
1.6 KiB
Ruby
Executable file

#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'
describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'should concat one array to another' do
pp = <<-EOS
$output = concat(['1','2','3'],['4','5','6'])
validate_array($output)
if size($output) != 6 {
fail("${output} should have 6 elements.")
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'should concat arrays and primitives to array' do
pp = <<-EOS
$output = concat(['1','2','3'],'4','5','6',['7','8','9'])
validate_array($output)
if size($output) != 9 {
fail("${output} should have 9 elements.")
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'should concat multiple arrays to one' do
pp = <<-EOS
$output = concat(['1','2','3'],['4','5','6'],['7','8','9'])
validate_array($output)
if size($output) != 9 {
fail("${output} should have 9 elements.")
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'should concat hash arguments' do
pp = <<-EOS
$output = concat([{"a" => "b"}], {"c" => "d", "e" => "f"})
validate_array($output)
if size($output) != 2 {
fail("${output} should have 2 elements.")
}
if $output[1] != {"c" => "d", "e" => "f"} {
fail("${output} does not have the expected hash for the second element.")
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end
end