Class: Asciidoctor::DocTest::RakeTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/asciidoctor/doctest/rake_tasks.rb

Overview

Rake tasks for testing and generating output examples.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks_namespace = :doctest) {|self| ... } ⇒ RakeTasks

Defines and configures :test and :generate rake tasks under the specified namespace.

Parameters:

  • tasks_namespace (#to_sym) (defaults to: :doctest)

    namespace for the :test and :generate tasks.

Yields:

  • (self)

    Gives self to the block.


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
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 92

def initialize(tasks_namespace = :doctest)
  @tasks_namespace = tasks_namespace
  @test_description = DEFAULT_TEST_DESC
  @generate_description = DEFAULT_GENERATE_DESC
  @input_examples = IO.create(:asciidoc)
  @converter_opts = {}
  @force = false
  @pattern = '*:*'

  yield self

  fail ArgumentError, 'The output_examples must be provided!' unless @output_examples

  @converter = converter.new(converter_opts) if converter.is_a? Class
  @test_reporter ||= TestReporter.new($stdout, verbose: verbose?,
    title: "Running DocTest for the #{subject}.")

  namespace(tasks_namespace) do
    define_test_task!
    define_generate_task!
  end

  desc "Alias for #{tasks_namespace}:test."
  task tasks_namespace => "#{tasks_namespace}:test"
end

Instance Attribute Details

#convertervoid

Returns the value of attribute converter


56
57
58
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 56

def converter
  @converter
end

#converter_optsHash

Returns options for the Asciidoctor converter.

Returns:

  • (Hash)

    options for the Asciidoctor converter.

See Also:


60
61
62
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 60

def converter_opts
  @converter_opts
end

#force=(value) ⇒ Boolean

Note:

Used only in the generator task.

Returns whether to rewrite an already existing testing example. May be overriden with FORCE variable on the command line (default: false).

Returns:

  • (Boolean)

    whether to rewrite an already existing testing example. May be overriden with FORCE variable on the command line (default: false).


81
82
83
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 81

def force=(value)
  @force = value
end

#generate_description#to_s, #call

Returns description of the generator task.

Returns:

  • (#to_s, #call)

    description of the generator task.


54
55
56
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 54

def generate_description
  @generate_description
end

#patternString

Returns glob pattern to select examples to test or (re)generate. May be overriden with PATTERN variable on the command line (default: *:*).

Returns:

  • (String)

    glob pattern to select examples to test or (re)generate. May be overriden with PATTERN variable on the command line (default: *:*).


65
66
67
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 65

def pattern
  @pattern
end

#tasks_namespace#to_sym

Returns namespace for the :test and :generate tasks. The :test task will be set as the default task of this namespace.

Returns:

  • (#to_sym)

    namespace for the :test and :generate tasks. The :test task will be set as the default task of this namespace.


48
49
50
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 48

def tasks_namespace
  @tasks_namespace
end

#test_description#to_s, #call

Returns description of the test task.

Returns:

  • (#to_s, #call)

    description of the test task.


51
52
53
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 51

def test_description
  @test_description
end

#test_reporterMinitest::Reporter

Note:

Used only in the test task.

Returns an instance of Reporter subclass to report test results.

Returns:

  • (Minitest::Reporter)

    an instance of Reporter subclass to report test results.


70
71
72
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 70

def test_reporter
  @test_reporter
end

#verbose=(value) ⇒ Boolean

Note:

Used only in the test task and with the default #test_reporter.

Returns whether to print out more details (default: false). May be overriden with VERBOSE variable on the command line.

Returns:

  • (Boolean)

    whether to print out more details (default: false). May be overriden with VERBOSE variable on the command line.


75
76
77
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 75

def verbose=(value)
  @verbose = value
end

Instance Method Details

#force?Boolean Also known as: force

Note:

Used only in the generator task.

Returns whether to rewrite an already existing testing example. May be overriden with FORCE variable on the command line (default: false).

Returns:

  • (Boolean)

    whether to rewrite an already existing testing example. May be overriden with FORCE variable on the command line (default: false).


160
161
162
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 160

def force?
  ENV.fetch('FORCE', @force.to_s).to_b
end

#input_examples(format, opts) ⇒ void #input_examples(io) ⇒ void

Specifies a reader for the input examples. Defaults to :asciidoc with the built-in reference examples.

Overloads:

  • #input_examples(format, opts) ⇒ void

    Parameters:

    • format (Symbol, String)
    • opts (Hash)

    Options Hash (opts):

  • #input_examples(io) ⇒ void

    Parameters:


131
132
133
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 131

def input_examples(*args)
  @input_examples = create_io(*args)
end

#output_examples(format, opts) ⇒ void #output_examples(io) ⇒ void

Specifies a reader/writer for the output examples (required).

Overloads:

  • #output_examples(format, opts) ⇒ void

    Parameters:

    • format (Symbol, String)
    • opts (Hash)

    Options Hash (opts):

    • :path (String, Array<String>)

      path of the directory (or multiple directories) where to look for the examples. Default is Asciidoctor::DocTest.examples_path.

    • :file_ext (String)

      the filename extension (e.g. .adoc) of the examples files. Default value depends on the specified format.

  • #output_examples(io) ⇒ void

    Parameters:


151
152
153
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 151

def output_examples(*args)
  @output_examples = create_io(*args)
end

#verbose?Boolean Also known as: verbose

Note:

Used only in the test task and with the default #test_reporter.

Returns whether to print out more details (default: false). May be overriden with VERBOSE variable on the command line.

Returns:

  • (Boolean)

    whether to print out more details (default: false). May be overriden with VERBOSE variable on the command line.


167
168
169
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 167

def verbose?
  ENV.fetch('VERBOSE', @verbose.to_s).to_b
end