diff --git a/spec/lib/strings_spec/module_helper.rb b/spec/lib/strings_spec/module_helper.rb new file mode 100644 index 0000000..77bc860 --- /dev/null +++ b/spec/lib/strings_spec/module_helper.rb @@ -0,0 +1,20 @@ +class PuppetModuleHelper +# Helper methods to handle file operations around generating and loading HTML + def self.using_module(path, modulename, &block) + Dir.mktmpdir do |tmp| + module_location = File.join(path, "examples", modulename) + FileUtils.cp_r(module_location, tmp) + old_dir = Dir.pwd + begin + Dir.chdir(tmp) + yield(tmp) + ensure + Dir.chdir(old_dir) + end + end + end + + def self.read_html(dir, modulename, file) + File.read(File.join(dir, modulename, 'doc', file)) + end +end diff --git a/spec/unit/puppet/face_spec.rb b/spec/unit/puppet/face_spec.rb index 015c051..f08e013 100644 --- a/spec/unit/puppet/face_spec.rb +++ b/spec/unit/puppet/face_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'lib/strings_spec/module_helper' require 'puppet/face/strings' require 'tmpdir' require 'stringio' @@ -51,61 +52,61 @@ describe Puppet::Face do it "should properly generate HTML for manifest comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'test.html')).to include("Class: test") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'test.html')).to include("Class: test") end end it "should properly generate HTML for 3x function comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'Puppet3xFunctions.html')).to include("This is the function documentation for `function3x`") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'Puppet3xFunctions.html')).to include("This is the function documentation for `function3x`") end end it "should properly generate HTML for 4x function comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'Puppet4xFunctions.html')).to include("This is a function which is used to test puppet strings") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'Puppet4xFunctions.html')).to include("This is a function which is used to test puppet strings") end end it "should create correct files for nested classes" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer.html')).to include("Puppet Class: outer") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle.html')).to include("Puppet Class: middle") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle/inner.html')).to include("Puppet Class: inner") end end it "should create proper namespace for nested classes" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer.html')).to include("Hostclass: outer") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle.html')).to include("Hostclass: outer::middle") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle/inner.html')).to include("Hostclass: outer::middle::inner") end end @@ -127,24 +128,5 @@ describe Puppet::Face do expect{Puppet::Face[:strings, :current].server}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.") end end - - # Helper methods to handle file operations around generating and loading HTML - def using_module(modulename, &block) - Dir.mktmpdir do |tmp| - module_location = File.join(File.dirname(__FILE__), "examples", modulename) - FileUtils.cp_r(module_location, tmp) - old_dir = Dir.pwd - begin - Dir.chdir(tmp) - yield(tmp) - ensure - Dir.chdir(old_dir) - end - end - end - - def read_html(dir, modulename, file) - File.read(File.join(dir, modulename, 'doc', file)) - end end diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp b/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp new file mode 100644 index 0000000..7d1a8ee --- /dev/null +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp @@ -0,0 +1,7 @@ +# @param [Float] ident identification +class foo( String $ident = "Bob" , Integer $age = 10, ) +{ + notify {'$ident':} + notify {'$age':} +} + diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb index 6759d22..4939b6e 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' +require 'lib/strings_spec/module_helper' +require 'puppet/face/strings' require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler' require 'strings_spec/parsing' @@ -59,4 +61,29 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do expect(namespace).to_not be_nil end + it "should not issue just one warning if the parameter types don't match." do + YARD::Registry.clear + # FIXME The type information here will change with the next version of + # puppet. `expected` is the output expected from the stable branch. The + # output from the master branch will use this instead: + # "...specifies the types [String] in file..." + expected = <<-output +[warn]: @param tag types do not match the code. The ident parameter is declared as types [\"Float\"] in the docstring, but the code specifies the types [Puppet::Pops::Types::PStringType] in file manifests/init.pp near line 2 +Files: 1 +Modules: 0 ( 0 undocumented) +Classes: 0 ( 0 undocumented) +Constants: 0 ( 0 undocumented) +Methods: 0 ( 0 undocumented) +Puppet Classes: 1 ( 0 undocumented) +Puppet Types: 0 ( 0 undocumented) + 100.00% documented + output + + expect { + PuppetModuleHelper.using_module(File.dirname(__FILE__),'test') do |tmp| + Dir.chdir('test') + Puppet::Face[:strings, :current].yardoc + end + }.to output(expected).to_stdout_from_any_process + end end