Summary
build_spec calls .join on the return value of Array#first without guarding against nil. If YARD ever returns a code object whose files array is empty, the call raises NoMethodError and the entire test-examples pipeline crashes.
Location
lib/yard/cli/test_examples.rb — build_spec
spec.filepath = "#{Dir.pwd}/#{example.object.files.first.join(':')}"
When can files be empty?
YARD::CodeObject#files returns an empty array for objects that YARD could not associate with a source location — for example:
- Objects defined entirely in C extensions loaded as
.so/.bundle files.
- Objects synthesised by YARD plugins or macros that do not set file information.
- Objects documented in a yard file (
.yardoc cache) whose original source has since been deleted.
All of these are unusual but can occur when users run yard test-examples against a project that mixes Ruby and native extensions.
Current behaviour
NoMethodError: undefined method 'join' for nil
from lib/yard/cli/test_examples.rb:…:in 'build_spec'
The crash surfaces as an unhandled exception from generate_tests, aborting the entire run rather than just skipping the offending example.
Proposed solution
Guard against a missing first entry and fall back to a placeholder:
spec.filepath = if (file_info = example.object.files.first)
"#{Dir.pwd}/#{file_info.join(':')}"
else
example.object.path
end
Or more concisely:
spec.filepath = example.object.files.first&.then { |f| "#{Dir.pwd}/#{f.join(':')}" } ||
example.object.path
The fallback of the YARD path ensures failure messages still identify the object even when no file location is available.
Acceptance criteria
Summary
build_speccalls.joinon the return value ofArray#firstwithout guarding againstnil. If YARD ever returns a code object whosefilesarray is empty, the call raisesNoMethodErrorand the entire test-examples pipeline crashes.Location
lib/yard/cli/test_examples.rb—build_specWhen can
filesbe empty?YARD::CodeObject#filesreturns an empty array for objects that YARD could not associate with a source location — for example:.so/.bundlefiles..yardoccache) whose original source has since been deleted.All of these are unusual but can occur when users run
yard test-examplesagainst a project that mixes Ruby and native extensions.Current behaviour
The crash surfaces as an unhandled exception from
generate_tests, aborting the entire run rather than just skipping the offending example.Proposed solution
Guard against a missing first entry and fall back to a placeholder:
Or more concisely:
The fallback of the YARD path ensures failure messages still identify the object even when no file location is available.
Acceptance criteria
build_specdoes not raise whenexample.object.filesis emptyspec.filepath