From 3a64f886ebb26d0db35c9a540621f9ccf27df3aa Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 19 Sep 2023 09:59:13 +0900 Subject: [PATCH] Fix error when `@option` with non-method --- spec/templates/tag_spec.rb | 12 ++++++++++++ templates/default/tags/html/option.erb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/templates/tag_spec.rb b/spec/templates/tag_spec.rb index 5fcf3ed93..5e5b641ab 100644 --- a/spec/templates/tag_spec.rb +++ b/spec/templates/tag_spec.rb @@ -49,4 +49,16 @@ module Foo; end .not_to raise_error end end + + describe "option tags on non-methods" do + it "does not display @option tags on non-method objects" do + YARD.parse_string <<-'eof' + # @option opts name [#to_s] ('bar') the name + module Foo; end + eof + + expect { Registry.at('Foo').format(html_options) } + .not_to raise_error + end + end end diff --git a/templates/default/tags/html/option.erb b/templates/default/tags/html/option.erb index 0a6babccf..64e3ac7ce 100644 --- a/templates/default/tags/html/option.erb +++ b/templates/default/tags/html/option.erb @@ -1,4 +1,4 @@ -<% if object.has_tag?(:option) %> +<% if object.has_tag?(:option) && object.respond_to?(:parameters) %> <% object.parameters.each do |param, default| %> <% tags = object.tags(:option).select {|x| x.name.to_s == param.to_s.sub(/^\*+|:$/, '') } %> <% next if tags.empty? %>