| 1 | #! /usr/bin/env ruby -S rspec
|
|---|
| 2 | require 'spec_helper_acceptance'
|
|---|
| 3 |
|
|---|
| 4 | describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
|---|
| 5 | describe 'success' do
|
|---|
| 6 | it 'parses valid json' do
|
|---|
| 7 | pp = <<-EOS
|
|---|
| 8 | $a = '{"hunter": "washere", "tests": "passing"}'
|
|---|
| 9 | $ao = parsejson($a)
|
|---|
| 10 | $tests = $ao['tests']
|
|---|
| 11 | notice(inline_template('tests are <%= @tests.inspect %>'))
|
|---|
| 12 | EOS
|
|---|
| 13 |
|
|---|
| 14 | apply_manifest(pp, :catch_failures => true) do |r|
|
|---|
| 15 | expect(r.stdout).to match(/tests are "passing"/)
|
|---|
| 16 | end
|
|---|
| 17 | end
|
|---|
| 18 | end
|
|---|
| 19 |
|
|---|
| 20 | describe 'failure' do
|
|---|
| 21 | it 'raises error on incorrect json' do
|
|---|
| 22 | pp = <<-EOS
|
|---|
| 23 | $a = '{"hunter": "washere", "tests": "passing",}'
|
|---|
| 24 | $ao = parsejson($a, 'tests are using the default value')
|
|---|
| 25 | notice(inline_template('a is <%= @ao.inspect %>'))
|
|---|
| 26 | EOS
|
|---|
| 27 |
|
|---|
| 28 | apply_manifest(pp, :catch_failures => true) do |r|
|
|---|
| 29 | expect(r.stdout).to match(/tests are using the default value/)
|
|---|
| 30 | end
|
|---|
| 31 | end
|
|---|
| 32 |
|
|---|
| 33 | it 'raises error on incorrect json' do
|
|---|
| 34 | pp = <<-EOS
|
|---|
| 35 | $a = '{"hunter": "washere", "tests": "passing",}'
|
|---|
| 36 | $ao = parsejson($a)
|
|---|
| 37 | notice(inline_template('a is <%= @ao.inspect %>'))
|
|---|
| 38 | EOS
|
|---|
| 39 |
|
|---|
| 40 | apply_manifest(pp, :expect_failures => true) do |r|
|
|---|
| 41 | expect(r.stderr).to match(/expected next name/)
|
|---|
| 42 | end
|
|---|
| 43 | end
|
|---|
| 44 |
|
|---|
| 45 | it 'raises error on incorrect number of arguments' do
|
|---|
| 46 | pp = <<-EOS
|
|---|
| 47 | $o = parsejson()
|
|---|
| 48 | EOS
|
|---|
| 49 |
|
|---|
| 50 | apply_manifest(pp, :expect_failures => true) do |r|
|
|---|
| 51 | expect(r.stderr).to match(/wrong number of arguments/i)
|
|---|
| 52 | end
|
|---|
| 53 | end
|
|---|
| 54 | end
|
|---|
| 55 | end
|
|---|