From 8549bf7eff555fbe75542af1dff8f2e9dc6bed62 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 26 Aug 2014 16:57:55 -0700 Subject: [PATCH] (PDOC-5) Test defined types and 4x functions Begin to test the YARD handlers written for the puppet language. Add basic tests for the defined type and puppet 4 function handlers. In addition, make changes to the spec helper to make it easier to work with YARD Registries for testing purposes. --- spec/spec_helper.rb | 12 +++++++ .../yardoc/yard/examples/defined_type.pp | 7 ++++ .../yardoc/yard/examples/puppet4_function.rb | 7 ++++ .../unit/puppetx/yardoc/yard/handlers_spec.rb | 33 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 spec/unit/puppetx/yardoc/yard/examples/defined_type.pp create mode 100644 spec/unit/puppetx/yardoc/yard/examples/puppet4_function.rb create mode 100644 spec/unit/puppetx/yardoc/yard/handlers_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 81921a0..002b026 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,18 @@ require 'mocha' require 'puppet' require 'rspec' +# This is neeeded so we can access a Registry if YARD creates one +require 'puppetx/yardoc/yard/plugin' +include YARD + RSpec.configure do |config| config.mock_with :mocha end + +# Borrwed from YARD spec helper +def parse_file(file, thisfile = __FILE__, log_level = log.level, ext = '.pp') + Registry.clear + path = File.join(File.dirname(thisfile), 'examples', file.to_s + ext) + YARD::Parser::SourceParser.parse(path, [], log_level) +end + diff --git a/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp b/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp new file mode 100644 index 0000000..6021a41 --- /dev/null +++ b/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp @@ -0,0 +1,7 @@ +define wibbly::wobbly ($wimey) { + Notify ($wimey) +} + +wibbly::wobbly{ + 'timey': wimey => stuff + } diff --git a/spec/unit/puppetx/yardoc/yard/examples/puppet4_function.rb b/spec/unit/puppetx/yardoc/yard/examples/puppet4_function.rb new file mode 100644 index 0000000..fc65f89 --- /dev/null +++ b/spec/unit/puppetx/yardoc/yard/examples/puppet4_function.rb @@ -0,0 +1,7 @@ +require 'puppet' + +Puppet::Functions.create_function(:puppet4_function) do + def puppet4_function(x,y) + x >= y ? x : y + end +end diff --git a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb new file mode 100644 index 0000000..e554347 --- /dev/null +++ b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'puppetx/yardoc/yard/handlers' + +describe Puppetx::Yardoc::YARD::Handlers do + describe "DefinedTypeHanlder" do + it "should add a defined type object in the Registry" do + parse_file :defined_type, __FILE__ + require 'pry' + #binding.pry + obj = Registry.at("wibbly::wobbly") + expect(obj.type).to be(:definedtype) + end + end + + describe "FutureParserDispatchHandler" do + before(:each) {parse_file :puppet4_function, __FILE__, log.level, '.rb'} + + it "should add a puppet namespace object to the Registry" do + namespace = Registry.at("FutureParserFunctions") + expect(namespace.type).to be(:puppetnamespace) + end + + it "should add a future parser function object to the Registry" do + function = Registry.at("FutureParserFunctions#puppet4_function") + expect(function.type).to be(:method) + end + + it "should add a method object to the Registry" do + method = Registry.at("#puppet4_function") + expect(method.type).to be(:method) + end + end +end