From eb948c4a0dc36790c5444fc236b0154c3d716c58 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Mon, 24 Aug 2015 22:00:18 +0300 Subject: [MODULES-2462] Improve parseyaml function * Add default value support Second argument will be returned if yaml cannot be parsed instead of false value * Update tests --- spec/acceptance/parseyaml_spec.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'spec/acceptance/parseyaml_spec.rb') diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb index 5819837..7946de0 100755 --- a/spec/acceptance/parseyaml_spec.rb +++ b/spec/acceptance/parseyaml_spec.rb @@ -16,20 +16,29 @@ describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o end end end + describe 'failure' do - it 'raises error on incorrect yaml' do + it 'returns the default value on incorrect yaml' do pp = <<-EOS $a = "---\nhunter: washere\ntests: passing\n:" - $o = parseyaml($a) + $o = parseyaml($a, {'tests' => 'using the default value'}) $tests = $o['tests'] notice(inline_template('tests are <%= @tests.inspect %>')) EOS - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/(syntax error|did not find expected key)/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/tests are "using the default value"/) end end - it 'raises error on incorrect number of arguments' + it 'raises error on incorrect number of arguments' do + pp = <<-EOS + $o = parseyaml() + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/wrong number of arguments/i) + end + end end end -- cgit v1.2.3 From 799c38e14e1583e676e2b25a9c1782fd40e29fff Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Mon, 21 Sep 2015 10:56:08 -0700 Subject: Fix backwards compatibility from #511 Maintain the old behavior in the case where the optional second parameter isn't passed. Also, adding arity is backwards incompatible since stdlib still supports 2.7, so remove that. --- spec/acceptance/parseyaml_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/acceptance/parseyaml_spec.rb') diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb index 7946de0..64511f1 100755 --- a/spec/acceptance/parseyaml_spec.rb +++ b/spec/acceptance/parseyaml_spec.rb @@ -31,6 +31,20 @@ describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o end end + it 'raises error on incorrect yaml' do + pp = <<-EOS + $a = "---\nhunter: washere\ntests: passing\n:" + $o = parseyaml($a) + $tests = $o['tests'] + notice(inline_template('tests are <%= @tests.inspect %>')) + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/(syntax error|did not find expected key)/) + end + end + + it 'raises error on incorrect number of arguments' do pp = <<-EOS $o = parseyaml() -- cgit v1.2.3