Class: Asciidoctor::DocTest::Tester
- Inherits:
-
Object
- Object
- Asciidoctor::DocTest::Tester
- Defined in:
- lib/asciidoctor/doctest/tester.rb
Defined Under Namespace
Classes: MinitestSingleTest
Instance Attribute Summary collapse
-
#reporter ⇒ Minitest::Reporter
readonly
An instance of minitest’s
Reporter
to report test results.
Instance Method Summary collapse
-
#initialize(input_suite, output_suite, converter, reporter = nil) ⇒ Tester
constructor
A new instance of Tester.
-
#run_tests(pattern: '*:*') ⇒ Object
Runs tests for all the input/output examples which name matches the pattern.
-
#test_example(input_exmpl, output_exmpl) ⇒ Object
Tests if the given reference input is matching the expected output after conversion through the tested backend.
Constructor Details
#initialize(input_suite, output_suite, converter, reporter = nil) ⇒ Tester
Returns a new instance of Tester.
33 34 35 36 37 38 |
# File 'lib/asciidoctor/doctest/tester.rb', line 33 def initialize(input_suite, output_suite, converter, reporter = nil) @input_suite = input_suite @output_suite = output_suite @converter = converter @reporter = reporter || TestReporter.new end |
Instance Attribute Details
#reporter ⇒ Minitest::Reporter (readonly)
Returns an instance of minitest’s Reporter
to report test results.
16 17 18 |
# File 'lib/asciidoctor/doctest/tester.rb', line 16 def reporter @reporter end |
Instance Method Details
#run_tests(pattern: '*:*') ⇒ Object
Runs tests for all the input/output examples which name matches the pattern. When some output example is missing, it’s reported as a skipped test.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/asciidoctor/doctest/tester.rb', line 48 def run_tests(pattern: '*:*') @reporter.start @input_suite.pair_with(@output_suite).each do |input, output| next if input.empty? || !input.name_match?(pattern) test_example input, output end @reporter.report @reporter.passed? end |
#test_example(input_exmpl, output_exmpl) ⇒ Object
Tests if the given reference input is matching the expected output after conversion through the tested backend.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/asciidoctor/doctest/tester.rb', line 67 def test_example(input_exmpl, output_exmpl) test_with_minitest input_exmpl.name do |test| if output_exmpl.empty? test.skip 'No expected output found' else actual, expected = @converter.convert_examples(input_exmpl, output_exmpl) msg = output_exmpl.desc.presence || input_exmpl.desc test.assert_equal expected, actual, msg end end end |