(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:
parent
d5ffc4d8da
commit
74a946fcfe
|
@ -1,7 +0,0 @@
|
|||
define wibbly::wobbly ($wimey) {
|
||||
Notify ($wimey)
|
||||
}
|
||||
|
||||
wibbly::wobbly{
|
||||
'timey': wimey => stuff
|
||||
}
|
|
@ -10,9 +10,9 @@ describe Puppetx::Yardoc::YARD::Handlers do
|
|||
YARD::Parser::SourceParser.parse(path, [], log_level)
|
||||
end
|
||||
|
||||
def parse(string)
|
||||
def parse(string, parser = :ruby)
|
||||
Registry.clear
|
||||
YARD::Parser::SourceParser.parse_string(string)
|
||||
YARD::Parser::SourceParser.parse_string(string, parser)
|
||||
end
|
||||
|
||||
RSpec::Matchers.define :document_a do |arguments|
|
||||
|
@ -39,11 +39,58 @@ describe Puppetx::Yardoc::YARD::Handlers do
|
|||
end
|
||||
end
|
||||
|
||||
#TODO: Split up tests for each handler into their own files
|
||||
describe "DefinedTypeHanlder" do
|
||||
it "should add a defined type object in the Registry" do
|
||||
parse_file :defined_type, __FILE__, log.level, '.pp'
|
||||
obj = Registry.at("wibbly::wobbly")
|
||||
expect(obj.type).to be(:definedtype)
|
||||
def the_definedtype()
|
||||
Registry.at("foo::bar")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue