File: generate_json_spec.rb

package info (click to toggle)
puppet-strings 4.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,412 kB
  • sloc: ruby: 7,324; makefile: 12
file content (63 lines) | stat: -rw-r--r-- 2,033 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'Generating JSON' do
  let(:test_module_path) do
    sut_module_path(/Module test/)
  end

  let(:remote_tmp_path) do
    sut_tmp_path
  end

  let(:expected) do
    {
      'puppet_classes' => [],
      'data_types' => [],
      'data_type_aliases' => [],
      'defined_types' => [],
      'resource_types' => [],
      'providers' => [],
      'puppet_functions' => [
        'name' => 'function3x',
        'file' => "#{test_module_path}/lib/puppet/parser/functions/function3x.rb",
        'line' => 3,
        'type' => 'ruby3x',
        'signatures' => [
          {
            'signature' => 'function3x()',
            'docstring' => {
              'text' => 'This is the function documentation for `function3x`',
              'tags' => [
                {
                  'tag_name' => 'return',
                  'text' => '',
                  'types' => ['Any']
                }
              ]
            }
          }
        ],
        'docstring' => {
          'text' => 'This is the function documentation for `function3x`',
          'tags' => ['tag_name' => 'return', 'text' => '', 'types' => ['Any']]
        },
        'source' => "Puppet::Parser::Functions.newfunction(:function3x, :doc => \"This is the function documentation for `function3x`\") do |args|\nend"
      ],
      'puppet_tasks' => [],
      'puppet_plans' => []
    }
  end

  it 'renders JSON to stdout when using --format json' do
    output = run_shell("puppet strings generate --format json \"#{test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
    expect(JSON.parse(output)).to eq(expected)
  end

  it 'writes JSON to a file when using --format json --out' do
    tmpfile = File.join(remote_tmp_path, 'json_output.json')
    run_shell("puppet strings generate --format json --out #{tmpfile} \"#{test_module_path}/lib/puppet/parser/functions/function3x.rb\"")
    expect(JSON.parse(file(tmpfile).content)).to eq(expected)
  end
end