(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:
parent
766fd57ebe
commit
8549bf7eff
|
@ -5,6 +5,18 @@ require 'mocha'
|
||||||
require 'puppet'
|
require 'puppet'
|
||||||
require 'rspec'
|
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|
|
RSpec.configure do |config|
|
||||||
config.mock_with :mocha
|
config.mock_with :mocha
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
define wibbly::wobbly ($wimey) {
|
||||||
|
Notify ($wimey)
|
||||||
|
}
|
||||||
|
|
||||||
|
wibbly::wobbly{
|
||||||
|
'timey': wimey => stuff
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'puppet'
|
||||||
|
|
||||||
|
Puppet::Functions.create_function(:puppet4_function) do
|
||||||
|
def puppet4_function(x,y)
|
||||||
|
x >= y ? x : y
|
||||||
|
end
|
||||||
|
end
|
|
@ -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
|
Loading…
Reference in New Issue