File: to_array_of_json_strings_spec.rb

package info (click to toggle)
puppet-module-nova 27.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,068 kB
  • sloc: ruby: 11,144; python: 33; makefile: 10; sh: 10
file content (41 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe 'to_array_of_json_strings' do
  it 'exists' do
    is_expected.not_to eq(nil)
  end

  it 'fails with no arguments' do
    is_expected.to run.with_params.and_raise_error(Puppet::ParseError)
  end

  it 'fails with too many arguments' do
    is_expected.to run.with_params('arg1', 'arg2').and_raise_error(Puppet::ParseError)
  end

  it 'fails with a formatted json string' do
    data = '{"valid": "json", "syntax": "here"}'
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'fails with a hash' do
    data = {:some => "entry"}
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'fails unless array does not have hashes' do
    data = ['{"valid": "json", "syntax": "here"}']
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'fails if array but only some entries are valid' do
    data = [{:some => "entry"}, '{"valid": "json", "syntax": "here"}']
    is_expected.to run.with_params(data).and_raise_error(Puppet::ParseError)
  end

  it 'works with an array of hashes' do
    data = [{:some => "entry"}, {:with => "data"}]
    retval = ['{"some":"entry"}','{"with":"data"}']
    is_expected.to run.with_params(data).and_return(retval)
  end
end