Merge pull request #26 from hkenney/issue/master/PDOC-27_3x_functions_should_accept_one_or_more_arguments
(PDOC-27) Don't require options for 3x functions
This commit is contained in:
commit
6f7a983dc7
4
Gemfile
4
Gemfile
|
@ -10,11 +10,11 @@ puppetversion = ENV['PUPPET_VERSION']
|
||||||
if puppetversion
|
if puppetversion
|
||||||
gem 'puppet', puppetversion
|
gem 'puppet', puppetversion
|
||||||
else
|
else
|
||||||
gem 'puppet', '~> 3.6.2'
|
gem 'puppet'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rspec'
|
gem "rspec", "~> 2.14.0", :require => false
|
||||||
gem 'mocha'
|
gem 'mocha'
|
||||||
gem 'puppetlabs_spec_helper'
|
gem 'puppetlabs_spec_helper'
|
||||||
gem 'rspec-html-matchers'
|
gem 'rspec-html-matchers'
|
||||||
|
|
|
@ -66,13 +66,20 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler < YA
|
||||||
|
|
||||||
name = process_element(name)
|
name = process_element(name)
|
||||||
|
|
||||||
opts = opts.map do |tuple|
|
# Don't try to process options if we don't have any
|
||||||
# Jump down into the S-Expression that represents a hashrocket, `=>`,
|
if !opts.nil?
|
||||||
# and the values on either side of it.
|
opts = opts.map do |tuple|
|
||||||
tuple.jump(:assoc).map{|e| process_element(e)}
|
# 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
|
||||||
|
|
||||||
|
options = Hash[opts]
|
||||||
|
else
|
||||||
|
options = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
[name, Hash[opts]]
|
[name, options]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sometimes the YARD parser returns Heredoc strings that start with `<-`
|
# Sometimes the YARD parser returns Heredoc strings that start with `<-`
|
||||||
|
|
|
@ -21,18 +21,18 @@ describe PuppetX::PuppetLabs::Strings::Pops do
|
||||||
let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"}
|
let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"}
|
||||||
let(:transformer) {PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new}
|
let(:transformer) {PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new}
|
||||||
|
|
||||||
describe "transform method" do
|
describe "transform method" do
|
||||||
it "should perform the correct transformation with parameter defaults" do
|
it "should perform the correct transformation with parameter defaults" do
|
||||||
model = parser.parse_string(manifest_default).current.definitions.first
|
model = parser.parse_string(manifest_default).current.definitions.first
|
||||||
statements = transformer.transform(model)
|
statements = transformer.transform(model)
|
||||||
expect(statements.parameters[0][0].class).to be(PuppetX::PuppetLabs::Strings::Pops::YARDStatement)
|
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
|
model = parser.parse_string(manifest).current.definitions.first
|
||||||
statements = transformer.transform(model)
|
statements = transformer.transform(model)
|
||||||
expect(statements.parameters[0][1].class).to be(NilClass)
|
expect(statements.parameters[0][1].class).to be(NilClass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,4 +51,13 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler d
|
||||||
expect(the_method).to document_a(:type => :method, :docstring => "")
|
expect(the_method).to document_a(:type => :method, :docstring => "")
|
||||||
expect(the_namespace).to document_a(:type => :puppetnamespace)
|
expect(the_namespace).to document_a(:type => :puppetnamespace)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue