Summary
normalize_example_lines calls .gsub directly on text without guarding against nil. If a YARD @example tag has no body (e.g. # @example with no indented content following it), tag.text is nil and the call raises NoMethodError: undefined method 'gsub' for nil. This crashes the entire test-examples pipeline.
Location
lib/yard/cli/test_examples.rb — normalize_example_lines
def normalize_example_lines(text)
text = text.gsub('# =>', '#=>')
text = text.gsub('#=>', "\n#=>")
text.split("\n").map(&:strip).reject(&:empty?)
end
Called from extract_expectations, which is called from build_spec:
spec.expectations = extract_expectations(example)
When can text be nil?
A bare @example tag with no indented content:
# @example
def some_method
# ...
end
YARD parses this as a tag with text = nil.
Also possible with a titled-but-empty example:
# @example Some title
def some_method
# ...
end
Current behavior
NoMethodError: undefined method 'gsub' for nil
from lib/yard/cli/test_examples.rb:…:in 'normalize_example_lines'
The crash aborts the entire run — no tests execute.
Proposed solution
Return an empty array early when text is nil or blank:
def normalize_example_lines(text)
return [] if text.nil? || text.strip.empty?
text = text.gsub('# =>', '#=>')
text = text.gsub('#=>', "\n#=>")
text.split("\n").map(&:strip).reject(&:empty?)
end
This produces an empty expectations array, which means the example evaluates with zero assertions — consistent with how a body-less example would behave if the text were just whitespace.
Acceptance criteria
Summary
normalize_example_linescalls.gsubdirectly ontextwithout guarding againstnil. If a YARD@exampletag has no body (e.g.# @examplewith no indented content following it),tag.textisniland the call raisesNoMethodError: undefined method 'gsub' for nil. This crashes the entiretest-examplespipeline.Location
lib/yard/cli/test_examples.rb—normalize_example_linesCalled from
extract_expectations, which is called frombuild_spec:When can
textbe nil?A bare
@exampletag with no indented content:YARD parses this as a tag with
text = nil.Also possible with a titled-but-empty example:
Current behavior
The crash aborts the entire run — no tests execute.
Proposed solution
Return an empty array early when
textis nil or blank:This produces an empty expectations array, which means the example evaluates with zero assertions — consistent with how a body-less example would behave if the text were just whitespace.
Acceptance criteria
@exampletags with no body do not crash the runner@example Some titletags with no body do not crash the runner