From c56d9fc27ae1559fb8ba35891de68d5ecb76601d Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 9 Sep 2014 14:57:31 -0700 Subject: [PATCH] (PDOC-2) Refactor tests for host class handler Update the tests around the host class handler so that they test several different examples as opposed to just one. Additionally, refactor the tests so that they are more detailed when it comes to checking if the Registry is in the correct state after code has been parsed. --- .../puppetx/yardoc/yard/examples/class.pp | 5 -- .../unit/puppetx/yardoc/yard/handlers_spec.rb | 59 +++++++++++++------ 2 files changed, 40 insertions(+), 24 deletions(-) delete mode 100644 spec/unit/puppetx/yardoc/yard/examples/class.pp diff --git a/spec/unit/puppetx/yardoc/yard/examples/class.pp b/spec/unit/puppetx/yardoc/yard/examples/class.pp deleted file mode 100644 index 512b39f..0000000 --- a/spec/unit/puppetx/yardoc/yard/examples/class.pp +++ /dev/null @@ -1,5 +0,0 @@ -class foo::bar { - file { '/test/file/path': - owner => 'baz', - } -} diff --git a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb index 177f679..4ba051b 100644 --- a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb +++ b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb @@ -4,12 +4,6 @@ require 'puppetx/yardoc/yard/handlers' describe Puppetx::Yardoc::YARD::Handlers do # TODO: Relocate/refactor helper methods - 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 - def parse(string, parser = :ruby) Registry.clear YARD::Parser::SourceParser.parse_string(string, parser) @@ -201,22 +195,49 @@ describe Puppetx::Yardoc::YARD::Handlers do expect(the_method).to document_a(:type => :method, :docstring => "") expect(the_namespace).to document_a(:type => :puppetnamespace) end - - it "should not add anything to the Registry if incorrect ruby code is present" do - parse <<-RUBY - # The summary - This is not ruby code - RUBY - - expect(Registry.all).to be_empty - end end describe "HostClassDefintion" do - before(:each) {parse_file :class, __FILE__, log.level, '.pp'} - it "should add a host class object to the Registry" do - hostclass = Registry.at("foo::bar") - expect(hostclass.type).to be(:hostclass) + def the_hostclass() + Registry.at("foo::bar") + end + + it "should parse single-line documentation strings before a given class" do + comment = "Class: foo::bar" + puppet_code = <<-PUPPET + # #{comment} + class foo::bar { } + PUPPET + + parse(puppet_code, :puppet) + + expect(the_hostclass).to document_a(:type => :hostclass, :docstring => comment) + end + + it "should parse multi-line documentation strings before a given class" do + puppet_code = <<-PUPPET + # Class: foo::bar + # + # This class does some stuff + class foo::bar { } + PUPPET + + parse(puppet_code, :puppet) + + comment = "Class: foo::bar\nThis class does some stuff" + expect(the_hostclass).to document_a(:type => :hostclass, :docstring => comment) + end + + it "should not parse documentation before a class if it is followed by a new line" do + puppet_code = <<-PUPPET + # Class: foo::bar + + class foo::bar { } + PUPPET + + parse(puppet_code, :puppet) + + expect(the_hostclass).to document_a(:type => :hostclass, :docstring => "") end end end