parsejson_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require 'spec_helper_acceptance'
  2. describe 'parsejson function' do
  3. describe 'success' do
  4. pp1 = <<-DOC
  5. $a = '{"hunter": "washere", "tests": "passing"}'
  6. $ao = parsejson($a)
  7. $tests = $ao['tests']
  8. notice(inline_template('tests are <%= @tests.inspect %>'))
  9. DOC
  10. it 'parses valid json' 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 = '{"hunter": "washere", "tests": "passing",}'
  19. $ao = parsejson($a, 'tests are using the default value')
  20. notice(inline_template('a is <%= @ao.inspect %>'))
  21. DOC
  22. it 'raises error on incorrect json - default value is used' do
  23. apply_manifest(pp2, :catch_failures => true) do |r|
  24. expect(r.stdout).to match(%r{tests are using the default value})
  25. end
  26. end
  27. pp3 = <<-DOC
  28. $a = '{"hunter": "washere", "tests": "passing",}'
  29. $ao = parsejson($a)
  30. notice(inline_template('a is <%= @ao.inspect %>'))
  31. DOC
  32. it 'raises error on incorrect json' do
  33. apply_manifest(pp3, :expect_failures => true) do |r|
  34. expect(r.stderr).to match(%r{expected next name})
  35. end
  36. end
  37. pp4 = <<-DOC
  38. $o = parsejson()
  39. DOC
  40. it 'raises error on incorrect number of arguments' do
  41. apply_manifest(pp4, :expect_failures => true) do |r|
  42. expect(r.stderr).to match(%r{wrong number of arguments}i)
  43. end
  44. end
  45. end
  46. end