From 8b3cdd3a518fcaf8307a63e7edaaf9c3f1ba73d1 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Wed, 8 Jul 2015 16:09:36 -0700 Subject: [PATCH] (PDOC-37) Add additional tests for parameter names * Test positive cases (warnings AREN'T printed when they shouldn't be) * Test puppet functions which use dispatches --- .../yard/puppet_4x_function_handler_spec.rb | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb index c59821c..65f1fb1 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb @@ -71,4 +71,74 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler d RUBY }.to output("#{expected_output_not_a_param}\n#{expected_output_also_not_a_param}\n").to_stdout_from_any_process end + + + it "should not issue a warning if the parameter names do match the docstring" do + expect { + parse <<-RUBY + # @param num_a [Integer] the first number to be compared + # @param num_b [Integer] the second number to be compared + Puppet::Functions.create_function(:max) do + def max(num_a, num_b) + num_a >= num_b ? num_a : num_b + end + end + RUBY + }.to output("").to_stdout_from_any_process + end + + + + it "should issue a warning if the parameter names do not match the " + + "docstring in dispatch method" do + expected_output_not_a_param = "[warn]: @param tag has unknown parameter" + + " name: not_a_param \n in file `(stdin)' near line 3" + expected_output_also_not_a_param = "[warn]: @param tag has unknown " + + "parameter name: also_not_a_param \n in file `(stdin)' near line 3" + expect { + parse <<-RUBY + # @param not_a_param Integer the first number to be compared + # @param also_not_a_param Integer the second number to be compared + Puppet::Functions.create_function(:max) do + dispatch max_1 do + param 'Integer', :num_a + param 'Integer', :num_b + end + + dispatch max_2 { + param 'String', :num_c + param 'String', :num_d + } + + def max_1(num_a, num_b) + num_a >= num_b ? num_a : num_b + end + + def max_2(num_a, num_b) + num_a >= num_b ? num_a : num_b + end + end + RUBY + }.to output("#{expected_output_not_a_param}\n#{expected_output_also_not_a_param}\n").to_stdout_from_any_process + end + + it "should not issue a warning if the parameter names do match the " + + "docstring in dispatch method" do + expect { + parse <<-RUBY + # @param num_a Integer the first number to be compared + # @param num_b Integer the second number to be compared + Puppet::Functions.create_function(:max) do + dispatch max_1 do + param 'Integer', :num_a + param 'Integer', :num_b + end + + def max_1(num_a, num_b) + num_a >= num_b ? num_a : num_b + end + end + RUBY + }.to output("").to_stdout_from_any_process + end end