pick_default_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. require 'spec_helper_acceptance'
  2. describe 'pick_default function' do
  3. describe 'success' do
  4. pp1 = <<-DOC
  5. $a = undef
  6. $o = pick_default($a, 'default')
  7. notice(inline_template('picked is <%= @o.inspect %>'))
  8. DOC
  9. it 'pick_defaults a default value' do
  10. apply_manifest(pp1, :catch_failures => true) do |r|
  11. expect(r.stdout).to match(%r{picked is "default"})
  12. end
  13. end
  14. pp2 = <<-DOC
  15. $a = undef
  16. $b = undef
  17. $o = pick_default($a,$b)
  18. notice(inline_template('picked is <%= @o.inspect %>'))
  19. DOC
  20. it 'pick_defaults with no value' do
  21. apply_manifest(pp2, :catch_failures => true) do |r|
  22. expect(r.stdout).to match(%r{picked is ""})
  23. end
  24. end
  25. pp3 = <<-DOC
  26. $a = "something"
  27. $b = "long"
  28. $o = pick_default($a, $b, 'default')
  29. notice(inline_template('picked is <%= @o.inspect %>'))
  30. DOC
  31. it 'pick_defaults the first set value' do
  32. apply_manifest(pp3, :catch_failures => true) do |r|
  33. expect(r.stdout).to match(%r{picked is "something"})
  34. end
  35. end
  36. end
  37. describe 'failure' do
  38. pp4 = <<-DOC
  39. $o = pick_default()
  40. notice(inline_template('picked is <%= @o.inspect %>'))
  41. DOC
  42. it 'raises error with no values' do
  43. apply_manifest(pp4, :expect_failures => true) do |r|
  44. expect(r.stderr).to match(%r{Must receive at least one argument})
  45. end
  46. end
  47. end
  48. end