From: Matt Robinson <[email protected]>

The structure of the AST has changed from 2.6.x to master, so the code
to generate documentation from the AST had to change.

Generating documentation for resources other than classes, nodes and
defines is still broken, see ticket #6634

Paired-with: Daniel Pittman <[email protected]>
Signed-off-by: Max Martin <[email protected]>
---
Local-branch: ticket/next/4798-rdoc-fixes
 lib/puppet/util/rdoc.rb               |   13 +-----
 spec/fixtures/unit/util/rdoc/basic.pp |   16 +++++++
 spec/unit/util/rdoc_spec.rb           |   70 +++++++-------------------------
 3 files changed, 35 insertions(+), 64 deletions(-)
 create mode 100644 spec/fixtures/unit/util/rdoc/basic.pp

diff --git a/lib/puppet/util/rdoc.rb b/lib/puppet/util/rdoc.rb
index bdac579..16d1fa1 100644
--- a/lib/puppet/util/rdoc.rb
+++ b/lib/puppet/util/rdoc.rb
@@ -53,17 +53,10 @@ module Puppet::Util::RDoc
   # of a manifest
   def output(file, ast)
     astobj = []
-    ast.nodes.each do |name, k|
-      astobj << k if k.file == file
+    ast.instantiate('').each do |resource_type|
+      astobj << resource_type if resource_type.file == file
     end
 
-    ast.hostclasses.each do |name,k|
-      astobj << k if k.file == file
-    end
-
-    ast.definitions.each do |name, k|
-      astobj << k if k.file == file
-    end
     astobj.sort! {|a,b| a.line <=> b.line }.each do |k|
       output_astnode_doc(k)
     end
@@ -89,4 +82,4 @@ module Puppet::Util::RDoc
     end
   end
 
-end
\ No newline at end of file
+end
diff --git a/spec/fixtures/unit/util/rdoc/basic.pp 
b/spec/fixtures/unit/util/rdoc/basic.pp
new file mode 100644
index 0000000..5616503
--- /dev/null
+++ b/spec/fixtures/unit/util/rdoc/basic.pp
@@ -0,0 +1,16 @@
+# im a class
+class foo {
+  file { '/tmp/foo' :
+    ensure => present,
+  }
+}
+
+# im a node
+node gar {
+}
+
+# im a define
+define baz { }
+
+# im a resource
+host { 'cow' : }
diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb
index 41d4b9c..93c4f9b 100755
--- a/spec/unit/util/rdoc_spec.rb
+++ b/spec/unit/util/rdoc_spec.rb
@@ -123,63 +123,25 @@ describe Puppet::Util::RDoc do
     end
 
     describe "when outputing documentation" do
-      before :each do
-        @node = stub 'node', :file => "file", :line => 1, :doc => ""
-        @class = stub 'class', :file => "file", :line => 4, :doc => ""
-        @definition = stub 'definition', :file => "file", :line => 3, :doc => 
""
-        @ast = stub 'ast', :nodes => { :node => @node }, :hostclasses => { 
:class => @class }, :definitions => { :definition => @definition }
-      end
-
-      it "should output doc for ast nodes" do
-        @node.expects(:doc)
-
-        Puppet::Util::RDoc.output("file", @ast)
-      end
-
-      it "should output doc for ast classes" do
-        @class.expects(:doc)
-
-        Puppet::Util::RDoc.output("file", @ast)
-      end
-
-      it "should output doc for ast definitions" do
-        @definition.expects(:doc)
-
-        Puppet::Util::RDoc.output("file", @ast)
-      end
-
-      it "should output doc in order of increasing line number" do
-        byline = sequence('byline')
-        @node.expects(:doc).in_sequence(byline)
-        @definition.expects(:doc).in_sequence(byline)
-        @class.expects(:doc).in_sequence(byline)
-
-        Puppet::Util::RDoc.output("file", @ast)
-      end
-
-      it "should not output documentation of ast object of another node" do
-        klass = stub 'otherclass', :file => "otherfile", :line => 12, :doc => 
""
-        @ast.stubs(:hostclasses).returns({ :otherclass => klass })
-
-        klass.expects(:doc).never
-
-        Puppet::Util::RDoc.output("file", @ast)
+      it "should output doc for ast classes, nodes and definitions in order of 
increasing line number" do
+        byline = sequence('documentation outputs in line order')
+        Puppet::Util::RDoc.expects(:puts).with("im a 
class\n").in_sequence(byline)
+        Puppet::Util::RDoc.expects(:puts).with("im a 
node\n").in_sequence(byline)
+        Puppet::Util::RDoc.expects(:puts).with("im a 
define\n").in_sequence(byline)
+        # any other output must fail
+        Puppet::Util::RDoc.manifestdoc([my_fixture('basic.pp')])
       end
 
       it "should output resource documentation if needed" do
-        Puppet.settings.stubs(:[]).with(:document_all).returns(true)
-        [@node,@definition].each do |o|
-          o.stubs(:code).returns([])
-        end
-
-        resource = stub_everything 'resource', :line => 1
-        
resource.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false)
-        
resource.stubs(:is_a?).with(Puppet::Parser::AST::Resource).returns(true)
-        @class.stubs(:code).returns([resource])
-
-        resource.expects(:doc)
-
-        Puppet::Util::RDoc.output("file", @ast)
+        pending "#6634 being fixed"
+        Puppet.settings[:document_all] = true
+        byline = sequence('documentation outputs in line order')
+        Puppet::Util::RDoc.expects(:puts).with("im a 
class\n").in_sequence(byline)
+        Puppet::Util::RDoc.expects(:puts).with("im a 
node\n").in_sequence(byline)
+        Puppet::Util::RDoc.expects(:puts).with("im a 
define\n").in_sequence(byline)
+        Puppet::Util::RDoc.expects(:puts).with("im a 
resource\n").in_sequence(byline)
+        # any other output must fail
+        Puppet::Util::RDoc.manifestdoc([my_fixture('basic.pp')])
       end
     end
   end
-- 
1.7.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to