(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.
This commit is contained in:
Hailee Kenney 2014-08-26 16:57:55 -07:00
parent 766fd57ebe
commit 8549bf7eff
4 changed files with 59 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
define wibbly::wobbly ($wimey) {
Notify ($wimey)
}
wibbly::wobbly{
'timey': wimey => stuff
}

View File

@ -0,0 +1,7 @@
require 'puppet'
Puppet::Functions.create_function(:puppet4_function) do
def puppet4_function(x,y)
x >= y ? x : y
end
end

View File

@ -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