|
3 | 3 | require 'spec_helper'
|
4 | 4 |
|
5 | 5 | describe 'parsepson' do
|
6 |
| - it 'exists' do |
7 |
| - is_expected.not_to eq(nil) |
8 |
| - end |
9 |
| - |
10 |
| - it 'raises an error if called without any arguments' do |
11 |
| - is_expected.to run.with_params |
12 |
| - .and_raise_error(%r{'parsepson' expects between 1 and 2 arguments, got none}i) |
13 |
| - end |
14 |
| - |
15 |
| - context 'with correct PSON data' do |
16 |
| - it 'is able to parse PSON data with a Hash' do |
17 |
| - is_expected.to run.with_params('{"a":"1","b":"2"}') |
18 |
| - .and_return('a' => '1', 'b' => '2') |
| 6 | + if Puppet::Util::Package.versioncmp(Puppet.version, '8.0.0').negative? |
| 7 | + it 'exists' do |
| 8 | + is_expected.not_to eq(nil) |
19 | 9 | end
|
20 | 10 |
|
21 |
| - it 'is able to parse PSON data with an Array' do |
22 |
| - is_expected.to run.with_params('["a","b","c"]') |
23 |
| - .and_return(['a', 'b', 'c']) |
| 11 | + it 'raises an error if called without any arguments' do |
| 12 | + is_expected.to run.with_params |
| 13 | + .and_raise_error(%r{'parsepson' expects between 1 and 2 arguments, got none}i) |
24 | 14 | end
|
25 | 15 |
|
26 |
| - it 'is able to parse empty PSON values' do |
27 |
| - actual_array = ['[]', '{}'] |
28 |
| - expected = [[], {}] |
29 |
| - actual_array.each_with_index do |actual, index| |
30 |
| - is_expected.to run.with_params(actual).and_return(expected[index]) |
| 16 | + context 'with correct PSON data' do |
| 17 | + it 'is able to parse PSON data with a Hash' do |
| 18 | + is_expected.to run.with_params('{"a":"1","b":"2"}') |
| 19 | + .and_return('a' => '1', 'b' => '2') |
31 | 20 | end
|
32 |
| - end |
33 | 21 |
|
34 |
| - it 'is able to parse PSON data with a mixed structure' do |
35 |
| - is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}') |
36 |
| - .and_return('a' => '1', 'b' => 2, 'c' => { 'd' => [true, false] }) |
37 |
| - end |
| 22 | + it 'is able to parse PSON data with an Array' do |
| 23 | + is_expected.to run.with_params('["a","b","c"]') |
| 24 | + .and_return(['a', 'b', 'c']) |
| 25 | + end |
38 | 26 |
|
39 |
| - it 'is able to parse PSON data with a UTF8 and double byte characters' do |
40 |
| - is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}') |
41 |
| - .and_return('×' => 'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] }) |
42 |
| - end |
| 27 | + it 'is able to parse empty PSON values' do |
| 28 | + actual_array = ['[]', '{}'] |
| 29 | + expected = [[], {}] |
| 30 | + actual_array.each_with_index do |actual, index| |
| 31 | + is_expected.to run.with_params(actual).and_return(expected[index]) |
| 32 | + end |
| 33 | + end |
43 | 34 |
|
44 |
| - it 'does not return the default value if the data was parsed correctly' do |
45 |
| - is_expected.to run.with_params('{"a":"1"}', 'default_value') |
46 |
| - .and_return('a' => '1') |
47 |
| - end |
48 |
| - end |
| 35 | + it 'is able to parse PSON data with a mixed structure' do |
| 36 | + is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}') |
| 37 | + .and_return('a' => '1', 'b' => 2, 'c' => { 'd' => [true, false] }) |
| 38 | + end |
49 | 39 |
|
50 |
| - context 'with incorrect PSON data' do |
51 |
| - it 'raises an error with invalid PSON and no default' do |
52 |
| - is_expected.to run.with_params('invalid') |
53 |
| - .and_raise_error(PSON::ParserError) |
54 |
| - end |
| 40 | + it 'is able to parse PSON data with a UTF8 and double byte characters' do |
| 41 | + is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}') |
| 42 | + .and_return('×' => 'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] }) |
| 43 | + end |
55 | 44 |
|
56 |
| - it 'returns the default value for an invalid PSON and a given default' do |
57 |
| - is_expected.to run.with_params('invalid', 'default_value') |
58 |
| - .and_return('default_value') |
| 45 | + it 'does not return the default value if the data was parsed correctly' do |
| 46 | + is_expected.to run.with_params('{"a":"1"}', 'default_value') |
| 47 | + .and_return('a' => '1') |
| 48 | + end |
59 | 49 | end
|
60 | 50 |
|
61 |
| - it 'supports a structure for a default value' do |
62 |
| - is_expected.to run.with_params('invalid', 'a' => '1') |
63 |
| - .and_return('a' => '1') |
| 51 | + context 'with incorrect PSON data' do |
| 52 | + it 'raises an error with invalid PSON and no default' do |
| 53 | + is_expected.to run.with_params('invalid') |
| 54 | + .and_raise_error(PSON::ParserError) |
| 55 | + end |
| 56 | + |
| 57 | + it 'returns the default value for an invalid PSON and a given default' do |
| 58 | + is_expected.to run.with_params('invalid', 'default_value') |
| 59 | + .and_return('default_value') |
| 60 | + end |
| 61 | + |
| 62 | + it 'supports a structure for a default value' do |
| 63 | + is_expected.to run.with_params('invalid', 'a' => '1') |
| 64 | + .and_return('a' => '1') |
| 65 | + end |
64 | 66 | end
|
65 | 67 | end
|
66 | 68 | end
|
0 commit comments