Class: YARD::CLI::TestExamples Private

Inherits:
Command
  • Object
show all
Defined in:
lib/yard/cli/test_examples.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implements the +yard test-examples+ command

Registered with YARD's command dispatcher so that running +yard test-examples [paths...] [options]+ invokes #run. The full pipeline is:

  1. #parse_files — expand the given paths/globs into +.rb+ file paths, defaulting to +app/+ and +lib/+ when none are given.
  2. #parse_examples — YARD-parse those files and collect every +@example+ tag from the registry.
  3. #add_pwd_to_path — ensure the current working directory is on +$LOAD_PATH+ so that +require+ calls inside examples resolve correctly.
  4. #generate_tests — convert each tag into a YardExampleTest::Example and register it as a +Minitest::Spec+.
  5. #run_tests — schedule the specs to run via +Minitest.autorun+ when the process exits.

Instance Method Summary collapse

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the one-line description of the command shown in +yard help+

Returns:

  • (String)

    the description string



49
50
51
# File 'lib/yard/cli/test_examples.rb', line 49

def description
  'Run @example tags as tests'
end

#run(*args)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Runs the command line, parsing arguments and generating tests

Parameters:

  • args (Array<String>)

    Switches are passed to minitest, everything else is treated as the list of directories/files or glob



60
61
62
63
64
65
66
# File 'lib/yard/cli/test_examples.rb', line 60

def run(*args)
  files = parse_files(args.grep_v(/^-/))
  examples = parse_examples(files)
  add_pwd_to_path
  generate_tests(examples)
  run_tests
end