Class: Asciidoctor::DocTest::RakeTasks
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Asciidoctor::DocTest::RakeTasks
- Defined in:
- lib/asciidoctor/doctest/rake_tasks.rb
Overview
Rake tasks for testing and generating output examples.
Instance Attribute Summary collapse
-
#converter ⇒ Object
Returns the value of attribute converter.
-
#converter_opts ⇒ Hash
Options for the Asciidoctor converter.
-
#force ⇒ Boolean
Whether to rewrite an already existing testing example.
-
#generate_description ⇒ #to_s, #call
Description of the generator task.
-
#pattern ⇒ String
Glob pattern to select examples to test or (re)generate.
-
#tasks_namespace ⇒ #to_sym
Namespace for the
:test
and:generate
tasks. -
#test_description ⇒ #to_s, #call
Description of the test task.
-
#test_reporter ⇒ Minitest::Reporter
An instance of
Reporter
subclass to report test results. -
#verbose ⇒ Boolean
Whether to print out more details (default: false).
Instance Method Summary collapse
-
#force? ⇒ Boolean
(also: #force)
Whether to rewrite an already existing testing example.
-
#initialize(tasks_namespace = :doctest) {|self| ... } ⇒ RakeTasks
constructor
Defines and configures
:test
and:generate
rake tasks under the specified namespace. -
#input_examples(*args) ⇒ Object
Specifies a reader for the input examples.
-
#output_examples(*args) ⇒ Object
Specifies a reader/writer for the output examples (required).
- #subject ⇒ Object
-
#verbose? ⇒ Boolean
(also: #verbose)
Whether to print out more details (default: false).
Constructor Details
#initialize(tasks_namespace = :doctest) {|self| ... } ⇒ RakeTasks
Defines and configures :test
and :generate
rake tasks under the specified namespace.
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
#converter ⇒ Object
Returns the value of attribute converter.
56 57 58 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 56 def converter @converter end |
#converter_opts ⇒ Hash
Returns options for the Asciidoctor converter.
60 61 62 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 60 def converter_opts @converter_opts end |
#force=(value) ⇒ Boolean
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).
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.
54 55 56 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 54 def generate_description @generate_description end |
#pattern ⇒ String
Returns 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.
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.
51 52 53 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 51 def test_description @test_description end |
#test_reporter ⇒ Minitest::Reporter
Used only in the test task.
Returns 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
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.
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
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).
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) ⇒ Object #input_examples(io) ⇒ Object
Specifies a reader for the input examples. Defaults to :asciidoc
with the built-in reference examples.
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) ⇒ Object #output_examples(io) ⇒ Object
Specifies a reader/writer for the output examples (required).
151 152 153 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 151 def output_examples(*args) @output_examples = create_io(*args) end |
#subject ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 174 def subject { converter: 'converter', template_dirs: 'templates', backend_name: 'backend' } .each do |key, desc| val = converter_opts[key] return "#{desc}: #{val}" if val end end |
#verbose? ⇒ Boolean Also known as: verbose
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.
167 168 169 |
# File 'lib/asciidoctor/doctest/rake_tasks.rb', line 167 def verbose? ENV.fetch('VERBOSE', @verbose.to_s).to_b end |