| 1 |
require 'spec_helper' |
| 2 |
|
| 3 |
describe 'to_array_of_json_strings' do |
| 4 |
it 'exists' do |
| 5 |
is_expected.not_to eq(nil) |
| 6 |
end |
| 7 |
|
| 8 |
it 'fails with no arguments' do |
| 9 |
is_expected.to run.with_params.and_raise_error(Puppet::ParseError) |
| 10 |
end |
| 11 |
|
| 12 |
it 'fails with too many arguments' do |
| 13 |
is_expected.to run.with_params('arg1', 'arg2').and_raise_error(Puppet::ParseError) |
| 14 |
end |
| 15 |
|
| 16 |
it 'fails with a formatted json string' do |
| 17 |
data = '{"valid": "json", "syntax": "here"}' |
| 18 |
is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError) |
| 19 |
end |
| 20 |
|
| 21 |
it 'fails with a hash' do |
| 22 |
data = {:some => "entry"} |
| 23 |
is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError) |
| 24 |
end |
| 25 |
|
| 26 |
it 'fails unless array does not have hashes' do |
| 27 |
data = ['{"valid": "json", "syntax": "here"}'] |
| 28 |
is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError) |
| 29 |
end |
| 30 |
|
| 31 |
it 'fails if array but only some entries are valid' do |
| 32 |
data = [{:some => "entry"}, '{"valid": "json", "syntax": "here"}'] |
| 33 |
is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError) |
| 34 |
end |
| 35 |
|
| 36 |
it 'works with an array of hashes' do |
| 37 |
data = [{:some => "entry"}, {:with => "data"}] |
| 38 |
retval = ['{"some":"entry"}','{"with":"data"}'] |
| 39 |
is_expected.to run.with_params(data).and_return(retval) |
| 40 |
end |
| 41 |
end |