/
method_helper_spec.rb
107 lines (94 loc) · 3.18 KB
/
method_helper_spec.rb
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
# frozen_string_literal: true
RSpec.describe YARD::Templates::Helpers::MethodHelper do
include YARD::Templates::Helpers::BaseHelper
include YARD::Templates::Helpers::MethodHelper
describe "#format_args" do
it "displays keyword arguments" do
params = [['a:', '1'], ['b:', '2'], ['**kwargs', nil]]
YARD.parse_string 'def foo; end'
allow(Registry.at('#foo')).to receive(:parameters) { params }
expect(format_args(Registry.at('#foo'))).to eq '(a: 1, b: 2, **kwargs)'
end
it "does not show &blockarg if no @param tag and has @yield" do
YARD.parse_string <<-'eof'
# @yield blah
def foo(&block); end
eof
expect(format_args(Registry.at('#foo'))).to eq ''
end
it "does not show &blockarg if no @param tag and has @yieldparam" do
YARD.parse_string <<-'eof'
# @yieldparam blah test
def foo(&block); end
eof
expect(format_args(Registry.at('#foo'))).to eq ''
end
it "shows &blockarg if @param block is documented (even with @yield)" do
YARD.parse_string <<-'eof'
# @yield [a,b]
# @yieldparam a test
# @param block test
def foo(&block) end
eof
expect(format_args(Registry.at('#foo'))).to eq '(&block)'
end
end
describe "#format_block" do
before { YARD::Registry.clear }
it "shows block for method with yield" do
YARD.parse_string <<-'eof'
def foo; yield(a, b, c) end
eof
expect(format_block(Registry.at('#foo'))).to eq "{|a, b, c| ... }"
end
it "shows block for method with @yieldparam tags" do
YARD.parse_string <<-'eof'
# @yieldparam _self me!
def foo; end
eof
expect(format_block(Registry.at('#foo'))).to eq "{|_self| ... }"
end
it "shows block for method with @yield but no types" do
YARD.parse_string <<-'eof'
# @yield blah
# @yieldparam a
def foo; end
# @yield blah
def foo2; end
eof
expect(format_block(Registry.at('#foo'))).to eq "{|a| ... }"
expect(format_block(Registry.at('#foo2'))).to eq "{ ... }"
end
it "shows block for method with @yield and types" do
YARD.parse_string <<-'eof'
# @yield [a, b, c] blah
# @yieldparam a
def foo; end
eof
expect(format_block(Registry.at('#foo'))).to eq "{|a, b, c| ... }"
end
end
describe "#format_constant" do
include YARD::Templates::Helpers::HtmlHelper
it "displays correctly constant values which are quoted symbols" do
YARD.parse_string %(
class TestFmtConst
Foo = :''
Bar = :BAR
Baz = :'B+z'
end
)
# html_syntax_highlight will be called by format_constant for
# Foo, Bar and Baz and in turn will enquire for options.highlight
expect(self).to receive(:options).exactly(3).times.and_return(
Options.new.update(:highlight => false)
)
foo, bar, baz = %w(Foo Bar Baz).map do |c|
Registry.at("TestFmtConst::#{c}").value
end
expect(format_constant(foo)).to eq ":''"
expect(format_constant(bar)).to eq ':BAR'
expect(format_constant(baz)).to eq ":'B+z'"
end
end
end