any2array_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require 'spec_helper_acceptance'
  2. describe 'any2array function' do
  3. describe 'success' do
  4. pp1 = <<-DOC
  5. $input = ''
  6. $output = any2array($input)
  7. validate_array($output)
  8. notify { "Output: ${output}": }
  9. DOC
  10. it 'creates an empty array' do
  11. apply_manifest(pp1, :catch_failures => true) do |r|
  12. expect(r.stdout).to match(%r{Notice: Output: })
  13. end
  14. end
  15. pp2 = <<-DOC
  16. $input = ['array', 'test']
  17. $output = any2array($input)
  18. validate_array($output)
  19. notify { "Output: ${output}": }
  20. DOC
  21. it 'leaves arrays modified' do
  22. apply_manifest(pp2, :catch_failures => true) do |r|
  23. expect(r.stdout).to match(%r{Notice: Output: (\[|)array(,\s|)test(\]|)})
  24. end
  25. end
  26. pp3 = <<-DOC
  27. $input = {'test' => 'array'}
  28. $output = any2array($input)
  29. validate_array($output)
  30. # Check each element of the array is a plain string.
  31. validate_string($output[0])
  32. validate_string($output[1])
  33. notify { "Output: ${output}": }
  34. DOC
  35. it 'turns a hash into an array' do
  36. apply_manifest(pp3, :catch_failures => true) do |r|
  37. expect(r.stdout).to match(%r{Notice: Output: (\[|)test(,\s|)array(\]|)})
  38. end
  39. end
  40. end
  41. end