Skip to content

Commit 8049bf4

Browse files
committed
Limiting PSON testing to Puppet 7
1 parent acd34d2 commit 8049bf4

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

spec/functions/parsepson_spec.rb

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,66 @@
33
require 'spec_helper'
44

55
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)
199
end
2010

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)
2414
end
2515

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')
3120
end
32-
end
3321

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
3826

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
4334

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
4939

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
5544

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
5949
end
6050

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
6466
end
6567
end
6668
end

0 commit comments

Comments
 (0)