parseyaml_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'spec_helper_acceptance'
  2. describe 'parseyaml function' do
  3. describe 'success' do
  4. pp1 = <<-DOC
  5. $a = "---\nhunter: washere\ntests: passing\n"
  6. $o = parseyaml($a)
  7. $tests = $o['tests']
  8. notice(inline_template('tests are <%= @tests.inspect %>'))
  9. DOC
  10. it 'parses valid yaml' do
  11. apply_manifest(pp1, :catch_failures => true) do |r|
  12. expect(r.stdout).to match(%r{tests are "passing"})
  13. end
  14. end
  15. end
  16. describe 'failure' do
  17. pp2 = <<-DOC
  18. $a = "---\nhunter: washere\ntests: passing\n:"
  19. $o = parseyaml($a, {'tests' => 'using the default value'})
  20. $tests = $o['tests']
  21. notice(inline_template('tests are <%= @tests.inspect %>'))
  22. DOC
  23. it 'returns the default value on incorrect yaml' do
  24. apply_manifest(pp2, :catch_failures => true) do |r|
  25. expect(r.stdout).to match(%r{tests are "using the default value"})
  26. end
  27. end
  28. pp3 = <<-DOC
  29. $a = "---\nhunter: washere\ntests: passing\n:"
  30. $o = parseyaml($a)
  31. $tests = $o['tests']
  32. notice(inline_template('tests are <%= @tests.inspect %>'))
  33. DOC
  34. it 'raises error on incorrect yaml' do
  35. apply_manifest(pp3, :expect_failures => true) do |r|
  36. expect(r.stderr).to match(%r{(syntax error|did not find expected key)})
  37. end
  38. end
  39. pp4 = <<-DOC
  40. $o = parseyaml()
  41. DOC
  42. it 'raises error on incorrect number of arguments' do
  43. apply_manifest(pp4, :expect_failures => true) do |r|
  44. expect(r.stderr).to match(%r{wrong number of arguments}i)
  45. end
  46. end
  47. end
  48. end