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
|
# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'
# $COPY = :method001
# $COPYT = :html
RSpec.describe YARD::Templates::Engine.template(:default, :method) do
before { Registry.clear }
shared_examples_for "all formats" do
it "renders html format correctly" do
html_equals(Registry.at('#m').format(html_options), @template)
end
it "renders text format correctly" do
text_equals(Registry.at('#m').format(text_options), @template)
end
end
describe "regular (deprecated) method" do
before do
@template = :method001
YARD.parse_string <<-'eof'
private
# Comments
# @param [Hash] x the x argument
# @option x [String] :key1 (default) first key
# @option x [Symbol] :key2 second key
# @return [String] the result
# @raise [Exception] hi!
# @deprecated for great justice
def m(x) end
alias x m
eof
end
it_should_behave_like "all formats"
end
describe "method with 1 overload" do
before do
@template = :method002
YARD.parse_string <<-'eof'
private
# Comments
# @overload m(x, y)
# @param [String] x parameter x
# @param [Boolean] y parameter y
def m(x) end
eof
end
it_should_behave_like "all formats"
end
describe "method with 2 overloads" do
before do
@template = :method003
YARD.parse_string <<-'eof'
private
# Method comments
# @overload m(x, y)
# Overload docstring
# @param [String] x parameter x
# @param [Boolean] y parameter y
# @overload m(x, y, z)
# @param [String] x parameter x
# @param [Boolean] y parameter y
# @param [Boolean] z parameter z
def m(*args) end
eof
end
it_should_behave_like "all formats"
end
describe "method void return" do
before do
@template = :method004
YARD.parse_string <<-'eof'
# @return [void]
def m(*args) end
eof
end
it_should_behave_like "all formats"
end
describe "method void return in an overload" do
before do
@template = :method005
YARD.parse_string <<-'eof'
# @overload m(a)
# @return [void]
# @overload m(b)
# @param [String] b hi
def m(*args) end
eof
end
it_should_behave_like "all formats"
end
describe "method with keyword arguments" do
before do
@template = :method006
YARD.parse_string <<-'eof'
# @param [String] x the x argument
# @param [Boolean] y the y argument
# @param [kword1] keyword 1
# @param [kword2] keyword 2
def m(x, y, *args, kword1: 123, kword2:, **) end
eof
end
it_should_behave_like "all formats"
end if RUBY_VERSION >= "2.1"
end
|