(PDOC-2) Refactor tests for defined type handler

Like the 4x function handler tests, the tests around the defined
type handler were not very specific and didn't use multiple examples.
Update the tests so that they do more than just ensure that the right
objects were added to the Registry and cover a few different cases
instead of just one.
This commit is contained in:
Hailee Kenney 2014-09-09 11:38:41 -07:00
parent d5ffc4d8da
commit 74a946fcfe
2 changed files with 53 additions and 13 deletions

View File

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

View File

@ -10,9 +10,9 @@ describe Puppetx::Yardoc::YARD::Handlers do
YARD::Parser::SourceParser.parse(path, [], log_level) YARD::Parser::SourceParser.parse(path, [], log_level)
end end
def parse(string) def parse(string, parser = :ruby)
Registry.clear Registry.clear
YARD::Parser::SourceParser.parse_string(string) YARD::Parser::SourceParser.parse_string(string, parser)
end end
RSpec::Matchers.define :document_a do |arguments| RSpec::Matchers.define :document_a do |arguments|
@ -39,11 +39,58 @@ describe Puppetx::Yardoc::YARD::Handlers do
end end
end end
#TODO: Split up tests for each handler into their own files
describe "DefinedTypeHanlder" do describe "DefinedTypeHanlder" do
it "should add a defined type object in the Registry" do def the_definedtype()
parse_file :defined_type, __FILE__, log.level, '.pp' Registry.at("foo::bar")
obj = Registry.at("wibbly::wobbly") end
expect(obj.type).to be(:definedtype)
it "should parse single-line documentation strings before a given defined type" do
comment = "Definition: foo::bar"
puppet_code = <<-PUPPET
# #{comment}
define foo::bar ($baz) { }
PUPPET
parse(puppet_code, :puppet)
expect(the_definedtype).to document_a(:type => :definedtype, :docstring => comment)
end
it "should parse multi-line documentation strings before a given defined type" do
puppet_code = <<-PUPPET
# Definition: foo::bar
#
# This class does some stuff
define foo::bar ($baz) { }
PUPPET
parse(puppet_code, :puppet)
comment = "Definition: foo::bar\nThis class does some stuff"
expect(the_definedtype).to document_a(:type => :definedtype, :docstring => comment)
end
it "should not parse documentation before a function if it is followed by a new line" do
puppet_code = <<-PUPPET
# Definition: foo::bar
define foo::bar ($baz) { }
PUPPET
parse(puppet_code, :puppet)
expect(the_definedtype).to document_a(:type => :definedtype, :docstring => "")
end
it "should not add anything to the Registry if incorrect puppet code is present" do
puppet_code = <<-PUPPET
# Definition: foo::bar
This is not puppet code
PUPPET
parse(puppet_code, :puppet)
expect(Registry.all).to be_empty
end end
end end