From c5e3d488da374763c77c1438d9ed6dca232713ff Mon Sep 17 00:00:00 2001 From: Will Hopper Date: Fri, 30 Sep 2016 16:33:10 -0700 Subject: [PATCH] (PDOC-106) Add acceptance test for --emit-json CLI options --- spec/acceptance/emit_json_options.rb | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/acceptance/emit_json_options.rb diff --git a/spec/acceptance/emit_json_options.rb b/spec/acceptance/emit_json_options.rb new file mode 100644 index 0000000..d1e99f3 --- /dev/null +++ b/spec/acceptance/emit_json_options.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' +require 'util' +require 'json' + +include PuppetStrings::Acceptance::Util + +describe 'Emitting JSON' do +expected = { + "puppet_classes" => [], + "defined_types" => [], + "resource_types" => [], + "providers" => [], + "puppet_functions" => [ + "name" => "function3x", + "file" => "/etc/puppet/modules/test/lib/puppet/parser/functions/function3x.rb", + "line" => 1, + "type" => "ruby3x", + "signature" => "function3x()", + "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" + ] +} + + it 'should emit JSON to stdout when using the --emit-json-stdout option' do + test_module_path = get_test_module_path(master, /Module test/) + on master, puppet('strings', 'generate', '--emit-json-stdout', "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") do + output = stdout.chomp + expect(JSON.parse(output)).to eq(expected) + end + end + + it 'should write JSON to a file when using the --emit-json option' do + test_module_path = get_test_module_path(master, /Module test/) + tmpfile = master.tmpfile('json_output.json') + on master, puppet('strings', 'generate', "--emit-json #{tmpfile}", "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") + output = read_file_on(master, tmpfile) + expect(JSON.parse(output)).to eq(expected) + end +end