File: stats_spec.rb

package info (click to toggle)
yard 0.9.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,720 kB
  • sloc: ruby: 31,354; javascript: 7,608; makefile: 21
file content (96 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# frozen_string_literal: true
require 'stringio'

RSpec.describe YARD::CLI::Stats do
  before do
    Registry.clear
    YARD.parse_string <<-eof
      class A
        CONST = 1

        def foo; end

        attr_reader :fooattr

        # Documented
        def bar; end
      end
      module B; end
    eof

    @main_stats =
      "Files:           1\n" \
      "Modules:         1 (    1 undocumented)\n" \
      "Classes:         1 (    1 undocumented)\n" \
      "Constants:       1 (    1 undocumented)\n" \
      "Attributes:      1 (    0 undocumented)\n" \
      "Methods:         2 (    1 undocumented)\n" \
      " 33.33% documented\n"

    @output = StringIO.new
    @stats = CLI::Stats.new(false)
    allow(@stats).to receive(:support_rdoc_document_file!).and_return([])
    allow(@stats).to receive(:yardopts).and_return([])
    allow(log).to receive(:puts) {|*args| @output << args.join("\n") << "\n" }
  end

  it "lists undocumented objects with --list-undoc when there are undocumented objects" do
    @stats.run('--list-undoc')
    expect(@output.string).to eq <<-eof
#{@main_stats}
Undocumented Objects:

(in file: (stdin))
A
A#foo
A::CONST
B
eof
  end

  it "lists no undocumented objects with --list-undoc when there is nothing undocumented" do
    Registry.clear
    YARD.parse_string <<-eof
      # documentation
      def foo; end
    eof
    @stats.run('--list-undoc')
    expect(@output.string).to eq "Files:           1\n" \
                                 "Modules:         0 (    0 undocumented)\n" \
                                 "Classes:         0 (    0 undocumented)\n" \
                                 "Constants:       0 (    0 undocumented)\n" \
                                 "Attributes:      0 (    0 undocumented)\n" \
                                 "Methods:         1 (    0 undocumented)\n" \
                                 " 100.00% documented\n"
  end

  it "lists undocumented objects in compact mode with --list-undoc --compact" do
    @stats.run('--list-undoc', '--compact')
    expect(@output.string).to eq <<-eof
#{@main_stats}
Undocumented Objects:
A            ((stdin):1)
A#foo        ((stdin):4)
A::CONST     ((stdin):2)
B            ((stdin):11)
eof
  end

  it "still lists stats with --quiet" do
    @stats.run('--quiet')
    expect(@output.string).to eq @main_stats
  end

  it "ignores everything with --no-public" do
    @stats.run('--no-public')
    expect(@output.string).to eq(
      "Files:           0\n" \
      "Modules:         0 (    0 undocumented)\n" \
      "Classes:         0 (    0 undocumented)\n" \
      "Constants:       0 (    0 undocumented)\n" \
      "Attributes:      0 (    0 undocumented)\n" \
      "Methods:         0 (    0 undocumented)\n" \
      " 100.00% documented\n"
    )
  end
end