From 5257ca4bed42c0ffdc5ab550a20aeb793c8d8ea9 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Thu, 12 Feb 2015 13:27:35 -0800 Subject: [PATCH 1/3] (PDOC-27) Don't require options for 3x functions Prior to this commit, the 3x function handler assumed that at least two arguments (the name and one or more additional arguments) were passed into newfunction when creating a 3x function. However that is not actually required, the only argument needed is the name. Update the 3x function handler so that it will not throw and exception if only one argument is given. --- .../yard/handlers/puppet_3x_function_handler.rb | 13 +++++++++---- .../strings/yard/puppet_3x_function_handler_spec.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb index 116c71b0b..1e1cea270 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb @@ -66,10 +66,15 @@ def process_parameters name = process_element(name) - opts = opts.map do |tuple| - # Jump down into the S-Expression that represents a hashrocket, `=>`, - # and the values on either side of it. - tuple.jump(:assoc).map{|e| process_element(e)} + # Don't try to process options if we don't have any + if !opts.nil? + opts = opts.map do |tuple| + # Jump down into the S-Expression that represents a hashrocket, `=>`, + # and the values on either side of it. + tuple.jump(:assoc).map{|e| process_element(e)} + end + else + opts = [[]] end [name, Hash[opts]] diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb index 3fa453cf8..0b586059c 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb @@ -51,4 +51,13 @@ def the_namespace() expect(the_method).to document_a(:type => :method, :docstring => "") expect(the_namespace).to document_a(:type => :puppetnamespace) end + + it "should process documentation if only one option is passed to newfunction" do + parse <<-RUBY + newfunction(:the_functiion) do |args| + end + RUBY + + expect(the_namespace).to document_a(:type => :puppetnamespace) + end end From 0a3c37373c94819c6b5cbfa25f30ced1462cf8d8 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Fri, 13 Feb 2015 10:55:12 -0800 Subject: [PATCH 2/3] (maint) Update Gemfile to use rspec 2.14.0 Prior to this commit, the Gemfile for strings did not specify which version of rspec to use. When it started using rspec 3, the tests that relied upon the rspec-html-matchers gem began to fail, likely because that gem is not yet compatible with the new version of rspec. Update the Gemfile so that we explicitly use an older version of rspec to prevent tests from failing. We will have to either wait for rspec-html-matchers to catch up or find a new way of testing the HTML output before we can update to rspec 3. --- Gemfile | 4 ++-- spec/unit/puppet_x/puppetlabs/strings/pops_spec.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index b37a72297..4ee0853a9 100644 --- a/Gemfile +++ b/Gemfile @@ -10,11 +10,11 @@ puppetversion = ENV['PUPPET_VERSION'] if puppetversion gem 'puppet', puppetversion else - gem 'puppet', '~> 3.6.2' + gem 'puppet' end group :test do - gem 'rspec' + gem "rspec", "~> 2.14.0", :require => false gem 'mocha' gem 'puppetlabs_spec_helper' gem 'rspec-html-matchers' diff --git a/spec/unit/puppet_x/puppetlabs/strings/pops_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/pops_spec.rb index 24e019319..d8ac5f26c 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/pops_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/pops_spec.rb @@ -21,18 +21,18 @@ let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"} let(:transformer) {PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new} - describe "transform method" do - it "should perform the correct transformation with parameter defaults" do + describe "transform method" do + it "should perform the correct transformation with parameter defaults" do model = parser.parse_string(manifest_default).current.definitions.first statements = transformer.transform(model) expect(statements.parameters[0][0].class).to be(PuppetX::PuppetLabs::Strings::Pops::YARDStatement) - end + end - it "should perform the correct transofmration without parameter defaults" do + it "should perform the correct transofmration without parameter defaults" do model = parser.parse_string(manifest).current.definitions.first statements = transformer.transform(model) expect(statements.parameters[0][1].class).to be(NilClass) - end + end end end end From 849c731511615cb9e6b6eca83f05a774415f2825 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 17 Feb 2015 11:28:26 -0800 Subject: [PATCH 3/3] (PDOC-27) Make fix compatible with Ruby 2x Prior to this commit, the fix for the 3x function issue was trying to create an empty hash by calling Hash[ [[]] ] which in Ruby 1.9.3 produced and empty hash. However this is not the case in Ruby 2.0 and up. Therefor, fix up the code so that it does not rely on Hash[ [[]] ] creating and empty hash. --- .../strings/yard/handlers/puppet_3x_function_handler.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb index 1e1cea270..7ae9bd3e6 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb @@ -73,11 +73,13 @@ def process_parameters # and the values on either side of it. tuple.jump(:assoc).map{|e| process_element(e)} end + + options = Hash[opts] else - opts = [[]] + options = {} end - [name, Hash[opts]] + [name, options] end # Sometimes the YARD parser returns Heredoc strings that start with `<-`