X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fparsejson_spec.rb;h=d03858479e98f4d8246c81729cc6dd89bce2d710;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=7b07e49884671304165820cac680d556860bf430;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/parsejson_spec.rb b/3rdparty/modules/stdlib/spec/functions/parsejson_spec.rb old mode 100755 new mode 100644 index 7b07e4988..d03858479 --- a/3rdparty/modules/stdlib/spec/functions/parsejson_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/parsejson_spec.rb @@ -1,69 +1,66 @@ require 'spec_helper' describe 'parsejson' do - it 'should exist' do + it 'exists' do is_expected.not_to eq(nil) end - it 'should raise an error if called without any arguments' do - is_expected.to run.with_params(). - and_raise_error(/wrong number of arguments/i) + it 'raises an error if called without any arguments' do + is_expected.to run.with_params + .and_raise_error(%r{wrong number of arguments}i) end context 'with correct JSON data' do - - it 'should be able to parse JSON data with a Hash' do - is_expected.to run.with_params('{"a":"1","b":"2"}'). - and_return({'a'=>'1', 'b'=>'2'}) + it 'is able to parse JSON data with a Hash' do + is_expected.to run.with_params('{"a":"1","b":"2"}') + .and_return('a' => '1', 'b' => '2') end - it 'should be able to parse JSON data with an Array' do - is_expected.to run.with_params('["a","b","c"]'). - and_return(['a', 'b', 'c']) + it 'is able to parse JSON data with an Array' do + is_expected.to run.with_params('["a","b","c"]') + .and_return(['a', 'b', 'c']) end - it 'should be able to parse empty JSON values' do - is_expected.to run.with_params('[]'). - and_return([]) - is_expected.to run.with_params('{}'). - and_return({}) + it 'is able to parse empty JSON values' do + actual_array = ['[]', '{}'] + expected = [[], {}] + actual_array.each_with_index do |actual, index| + is_expected.to run.with_params(actual).and_return(expected[index]) + end end - it 'should be able to parse JSON data with a mixed structure' do - is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}'). - and_return({'a' =>'1', 'b' => 2, 'c' => { 'd' => [true, false] } }) + it 'is able to parse JSON data with a mixed structure' do + is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}') + .and_return('a' => '1', 'b' => 2, 'c' => { 'd' => [true, false] }) end - it 'should be able to parse JSON data with a UTF8 and double byte characters' do - is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}'). - and_return({'×' =>'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] } }) + it 'is able to parse JSON data with a UTF8 and double byte characters' do + is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}') + .and_return('×' => 'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] }) end - it 'should not return the default value if the data was parsed correctly' do - is_expected.to run.with_params('{"a":"1"}', 'default_value'). - and_return({'a' => '1'}) + it 'does not return the default value if the data was parsed correctly' do + is_expected.to run.with_params('{"a":"1"}', 'default_value') + .and_return('a' => '1') end - end context 'with incorrect JSON data' do - it 'should raise an error with invalid JSON and no default' do - is_expected.to run.with_params(''). - and_raise_error(PSON::ParserError) + it 'raises an error with invalid JSON and no default' do + is_expected.to run.with_params('') + .and_raise_error(PSON::ParserError) end - it 'should support a structure for a default value' do - is_expected.to run.with_params('', {'a' => '1'}). - and_return({'a' => '1'}) + it 'supports a structure for a default value' do + is_expected.to run.with_params('', 'a' => '1') + .and_return('a' => '1') end ['', 1, 1.2, nil, true, false, [], {}, :yaml].each do |value| it "should return the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do - is_expected.to run.with_params(value, 'default_value'). - and_return('default_value') + is_expected.to run.with_params(value, 'default_value') + .and_return('default_value') end end - end - end