|
27 | 27 |
|
28 | 28 | before(:each) do
|
29 | 29 | allow(File).to receive(:exists?).with(filename).and_return(false).once
|
30 |
| - allow(PSON).to receive(:load).never |
| 30 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 31 | + allow(PSON).to receive(:load).never |
| 32 | + else |
| 33 | + allow(JSON).to receive(:parse).never |
| 34 | + end |
31 | 35 | end
|
32 | 36 | it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
|
33 | 37 | it { is_expected.to run.with_params(filename, 'đẽƒằưļŧ' => '٧ẵłựέ').and_return('đẽƒằưļŧ' => '٧ẵłựέ') }
|
|
49 | 53 | allow(File).to receive(:exists?).with(filename).and_return(true).once
|
50 | 54 | allow(File).to receive(:read).with(filename).and_return(json).once
|
51 | 55 | allow(File).to receive(:read).with(filename).and_return(json).once
|
52 |
| - allow(PSON).to receive(:load).with(json).and_return(data).once |
| 56 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 57 | + allow(PSON).to receive(:load).with(json).and_return(data).once |
| 58 | + else |
| 59 | + allow(JSON).to receive(:parse).with(json).and_return(data).once |
| 60 | + end |
53 | 61 | end
|
54 | 62 | it { is_expected.to run.with_params(filename).and_return(data) }
|
55 | 63 | end
|
|
67 | 75 | before(:each) do
|
68 | 76 | allow(File).to receive(:exists?).with(filename).and_return(true).once
|
69 | 77 | allow(File).to receive(:read).with(filename).and_return(json).once
|
70 |
| - allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 78 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 79 | + allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 80 | + else |
| 81 | + allow(JSON).to receive(:parse).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 82 | + end |
71 | 83 | end
|
72 | 84 | it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
|
73 | 85 | end
|
|
80 | 92 | let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
|
81 | 93 |
|
82 | 94 | it {
|
83 |
| - expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json) |
84 |
| - expect(PSON).to receive(:load).with(json).and_return(data).once |
| 95 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 96 | + expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json) |
| 97 | + expect(PSON).to receive(:load).with(json).and_return(data).once |
| 98 | + else |
| 99 | + expect(URI).to receive(:open).with(filename).and_return(json) |
| 100 | + expect(JSON).to receive(:parse).with(json).and_return(data).once |
| 101 | + end |
85 | 102 | is_expected.to run.with_params(filename).and_return(data)
|
86 | 103 | }
|
87 | 104 | end
|
|
96 | 113 | let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
|
97 | 114 |
|
98 | 115 | it {
|
99 |
| - expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json) |
100 |
| - expect(PSON).to receive(:load).with(json).and_return(data).once |
| 116 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 117 | + expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json) |
| 118 | + expect(PSON).to receive(:load).with(json).and_return(data).once |
| 119 | + else |
| 120 | + expect(URI).to receive(:open).with(url_no_auth, basic_auth).and_return(json) |
| 121 | + expect(JSON).to receive(:parse).with(json).and_return(data).once |
| 122 | + end |
101 | 123 | is_expected.to run.with_params(filename).and_return(data)
|
102 | 124 | }
|
103 | 125 | end
|
|
112 | 134 | let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
|
113 | 135 |
|
114 | 136 | it {
|
115 |
| - expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json) |
116 |
| - expect(PSON).to receive(:load).with(json).and_return(data).once |
| 137 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 138 | + expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json) |
| 139 | + expect(PSON).to receive(:load).with(json).and_return(data).once |
| 140 | + else |
| 141 | + expect(URI).to receive(:open).with(url_no_auth, basic_auth).and_return(json) |
| 142 | + expect(JSON).to receive(:parse).with(json).and_return(data).once |
| 143 | + end |
117 | 144 | is_expected.to run.with_params(filename).and_return(data)
|
118 | 145 | }
|
119 | 146 | end
|
|
125 | 152 | let(:json) { ',;{"key":"value"}' }
|
126 | 153 |
|
127 | 154 | it {
|
128 |
| - expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json) |
129 |
| - expect(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 155 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 156 | + expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json) |
| 157 | + expect(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 158 | + else |
| 159 | + expect(URI).to receive(:open).with(filename).and_return(json) |
| 160 | + expect(JSON).to receive(:parse).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 161 | + end |
130 | 162 | is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
|
131 | 163 | }
|
132 | 164 | end
|
|
137 | 169 | end
|
138 | 170 |
|
139 | 171 | it {
|
140 |
| - expect(OpenURI).to receive(:open_uri).with(filename, {}).and_raise OpenURI::HTTPError, '404 File not Found' |
| 172 | + if Puppet::PUPPETVERSION[0].to_i < 8 |
| 173 | + expect(OpenURI).to receive(:open_uri).with(filename, {}).and_raise OpenURI::HTTPError, '404 File not Found' |
| 174 | + else |
| 175 | + expect(URI).to receive(:open).with(filename).and_raise URI::Error, '404 File not Found' |
| 176 | + end |
141 | 177 | is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
|
142 | 178 | }
|
143 | 179 | end
|
|
0 commit comments