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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'
RSpec.describe YARD::Templates::Engine.template(:default, :module) do
before do
Registry.clear
YARD.parse_string <<-'eof'
module B
def c; end
def d; end
private
def e; end
end
module BaseMod
attr_reader :base_attr1
attr_writer :base_attr2
attr_accessor :base_attr3
end
# Comments
module A
include BaseMod
attr_accessor :attr1
attr_reader :attr2
# @overload attr3
# @return [String] a string
# @overload attr3=(value)
# @param [String] value sets the string
# @return [void]
attr_accessor :attr3
attr_writer :attr4
def self.a; end
def a; end
alias b a
# @overload test_overload(a)
# hello2
# @param [String] a hi
def test_overload(*args) end
# @overload test_multi_overload(a)
# @overload test_multi_overload(a, b)
def test_multi_overload(*args) end
# @return [void]
def void_meth; end
include B
class Y; end
class Q; end
class X; end
module Z; end
# A long docstring for the constant. With extra text
# and newlines.
CONSTANT = 'value'
@@cvar = 'value' # @deprecated
end
module TMP; include A end
class TMP2; extend A end
eof
end
it "renders html format correctly" do
html_equals(Registry.at('A').format(html_options(:hide_void_return => true,
:verifier => Verifier.new('object.type != :method || object.visibility == :public'))),
:module001)
end
it "renders text format correctly" do
YARD.parse_string <<-'eof'
module A
include D, E, F, A::B::C
end
eof
text_equals(Registry.at('A').format(text_options), :module001)
end
it "renders dot format correctly" do
expect(Registry.at('A').format(:format => :dot, :dependencies => true, :full => true)).to eq example_contents(:module001, 'dot')
end
it "renders groups correctly in html" do
Registry.clear
YARD.parse_string <<-'eof'
module A
# @group Foo
attr_accessor :foo_attr
def foo; end
def self.bar; end
# @group Bar
def baz; end
# @endgroup
def self.baz; end
end
eof
html_equals(Registry.at('A').format(html_options), :module002)
end
it "ignores overwritten/private attributes/constants from inherited list" do
Registry.clear
YARD.parse_string <<-'eof'
module B
attr_reader :foo
attr_accessor :bar
# @private
attr_writer :baz
FOO = 1
end
module A
include B
def foo; end
attr_reader :bar
FOO = 2
end
eof
html_equals(Registry.at('A').
format(html_options(:verifier => Verifier.new('!@private'))), :module003)
end
it "embeds mixins with :embed_mixins = ['Foo', 'Bar', 'Baz::A*']" do
Registry.clear
YARD.parse_string <<-'eof'
class A
# This method is in A
def foo; end
include Foo
extend Bar
include BarFooBar
include Baz::XYZ
include Baz::ABC
end
module BarFooBar
def bar_foo_bar; end
end
module Foo
def self.not_included; end
# Docs for xyz
def xyz; end
# Docs for bar_attr
attr_accessor :bar_attr
end
module Bar
def self.not_included; end
# @group Booya
# Docs for baz in Booya group
def baz; end
end
module Baz
module XYZ
# listed as inherited
def baz_xyz; end
end
module ABC
def baz_abc; end
end
end
eof
html_equals(Registry.at('A').format(html_options(:embed_mixins => ['Foo', 'Bar', 'Baz::A*'])), :module004)
end
it "renders constant groups correctly in html" do
Registry.clear
YARD.parse_string <<-'eof'
module A
# @group Foo
FOO = 1
# @deprecated
BAR = 2
# @group Bar
BAZ = 3
# @endgroup
WORLD = 4
end
eof
html_equals(Registry.at('A').format(html_options), :module005)
end
end
|