From 74a946fcfe5c0467d01cde3e0217fb680fc0a203 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 9 Sep 2014 11:38:41 -0700 Subject: [PATCH] (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. --- .../yardoc/yard/examples/defined_type.pp | 7 --- .../unit/puppetx/yardoc/yard/handlers_spec.rb | 59 +++++++++++++++++-- 2 files changed, 53 insertions(+), 13 deletions(-) delete mode 100644 spec/unit/puppetx/yardoc/yard/examples/defined_type.pp diff --git a/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp b/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp deleted file mode 100644 index 6021a41..0000000 --- a/spec/unit/puppetx/yardoc/yard/examples/defined_type.pp +++ /dev/null @@ -1,7 +0,0 @@ -define wibbly::wobbly ($wimey) { - Notify ($wimey) -} - -wibbly::wobbly{ - 'timey': wimey => stuff - } diff --git a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb index 37098c2..b317ce6 100644 --- a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb +++ b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb @@ -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