asciidoctor-doctest 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +32 -0
  3. data/README.adoc +17 -12
  4. data/Rakefile +28 -3
  5. data/features/README +1 -0
  6. data/features/fixtures/html-slim/Rakefile +15 -0
  7. data/features/fixtures/html-slim/examples/asciidoc/block_quote.adoc +12 -0
  8. data/features/fixtures/html-slim/examples/asciidoc/document.adoc +4 -0
  9. data/features/fixtures/html-slim/examples/asciidoc/inline_quoted.adoc +2 -0
  10. data/features/fixtures/html-slim/examples/html/block_quote.html +26 -0
  11. data/features/fixtures/html-slim/examples/html/document.html +7 -0
  12. data/features/fixtures/html-slim/templates/block_paragraph.html.slim +1 -0
  13. data/features/fixtures/html-slim/templates/block_quote.html.slim +7 -0
  14. data/features/fixtures/html-slim/templates/document.html.slim +13 -0
  15. data/features/fixtures/html-slim/templates/embedded.html.slim +3 -0
  16. data/features/fixtures/html-slim/templates/inline_quoted.html.slim +8 -0
  17. data/features/fixtures/html-slim/test/html_test.rb +6 -0
  18. data/features/fixtures/html-slim/test/test_helper.rb +5 -0
  19. data/features/generator_html.feature +171 -0
  20. data/features/step_definitions/doctest_steps.rb +5 -0
  21. data/features/support/env.rb +21 -0
  22. data/features/test_html.feature +59 -0
  23. data/lib/asciidoctor/doctest/asciidoc_renderer.rb +19 -14
  24. data/lib/asciidoctor/doctest/base_example.rb +11 -5
  25. data/lib/asciidoctor/doctest/base_examples_suite.rb +1 -1
  26. data/lib/asciidoctor/doctest/generator.rb +3 -1
  27. data/lib/asciidoctor/doctest/generator_task.rb +8 -5
  28. data/lib/asciidoctor/doctest/html/example.rb +1 -1
  29. data/lib/asciidoctor/doctest/html/examples_suite.rb +2 -2
  30. data/lib/asciidoctor/doctest/minitest_diffy.rb +1 -1
  31. data/lib/asciidoctor/doctest/test.rb +4 -1
  32. data/lib/asciidoctor/doctest/version.rb +1 -1
  33. data/spec/asciidoc_renderer_spec.rb +98 -0
  34. data/spec/base_example_spec.rb +4 -1
  35. data/spec/html/examples_suite_spec.rb +5 -5
  36. data/spec/minitest_diffy_spec.rb +57 -0
  37. data/spec/shared_examples/base_examples_suite.rb +0 -20
  38. data/spec/support/fakefs.rb +19 -0
  39. metadata +151 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc9498892db6acc24257809bff779818ee7472f4
4
- data.tar.gz: a8a13d69add1fe26c44d6bb14c5931e521f73aff
3
+ metadata.gz: 479daec9ac0dc0ec44479eb7675e59a7bc17889d
4
+ data.tar.gz: ee45df8e137d9e67c1e042f132b4c729bd3c021d
5
5
  SHA512:
6
- metadata.gz: 3afb3a87af3908787ca1a3b6e450217ee6e38e4b3fd7d454c2547d60197b3f657b2b5efe024e1fb4317dd77660df9421896905806df9829ea125e3393a51f607
7
- data.tar.gz: ffa8177c85f0437636060d786b2174cb4dbb42624b17b45cfa4b81c38fc8bd030f35ae36bb9fc3e6918efc7efda4ed0aed336277cb718fcb54582629da797556
6
+ metadata.gz: 6e5edb9b2d8b24065e3546422d93be5632ae76295cefad0d60b502ced846bad0e5144974e4e4f64dc35832ef08c5b222a2b7e78204424d4c73a645c98a40c3be
7
+ data.tar.gz: d76d62985066c12587a7233d2546a5c923aa97a4578eb5e3895c930aa986a00ad5bcbf0f6b1c5f7addf75310f2a4ff6fddcb245572dca26e61a0c9d178a0e75d
data/CHANGELOG.adoc CHANGED
@@ -0,0 +1,32 @@
1
+ = Asciidoctor::DocTest Changelog
2
+ :repo-uri: https://github.com/asciidoctor/asciidoctor-doctest
3
+ :commit-uri: {repo-uri}/commit
4
+ :issue-uri: {repo-uri}/issues
5
+
6
+ This document provides a high-level view of the changes introduced in DocTest by release.
7
+ For a detailed view of what has changed, refer to the {repo-uri}/commits/master[commit history] on GitHub.
8
+
9
+
10
+ == 1.5.1 (2014-12-29)
11
+
12
+ Improvements::
13
+ * Rename parameter `renderer_opts` to `converter_opts` and method `render` to `convert` to be consistent with Asciidoctor (old names are aliased for now). {issue-uri}/2[#2] [{commit-uri}/97c06af[97c06af]]
14
+ * Rename `to_s` to `content_pretty` in BaseExample and make alias. [{commit-uri}/3b610e2[3b610e2]]
15
+
16
+ Bug fixes::
17
+ * Allow to modify default `examples_path` in GeneratorTask (was frozen). [{commit-uri}/7251e6c[7251e6c]]
18
+ * Fix `template_dirs` validation and default `backend_name` in AsciidocRenderer. [{commit-uri}/2a4413d[2a4413d]]
19
+ * Beautify generated HTML examples. [{commit-uri}/e9d42be[e9d42be]]
20
+ * Fix Generator to not lose description of the updated example. [{commit-uri}/0d2f4ee[0d2f4ee]]
21
+
22
+ Tests::
23
+ * Add end-to-end integration tests using Cucumber.
24
+ * Increase (unit) test coverage from 84.2% to 88.5%.
25
+
26
+ Known issues::
27
+ * HTML beautifier doesn’t work as expected. {issue-uri}/3[#3]
28
+
29
+
30
+ == 1.5.0 (2014-12-09)
31
+
32
+ The first stable release.
data/README.adoc CHANGED
@@ -6,23 +6,28 @@ ifdef::env-github[:idprefix: user-content-]
6
6
  :idseparator: -
7
7
  :source-language: ruby
8
8
  :language: {source-language}
9
- // links
9
+ // custom
10
+ :gem-name: asciidoctor-doctest
11
+ :gh-name: asciidoctor/{gem-name}
12
+ :gh-branch: master
13
+ :badge-style: flat
10
14
  :doctor-man-uri: http://asciidoctor.org/docs/user-manual
15
+ :rawgit-base: https://cdn.rawgit.com/{gh-name}/master
11
16
  :src-base: lib/asciidoctor/doctest
12
17
 
13
- image:https://travis-ci.org/asciidoctor/asciidoctor-doctest.svg?branch=master[Build Status, link=https://travis-ci.org/asciidoctor/asciidoctor-doctest]
14
- image:https://codeclimate.com/github/asciidoctor/asciidoctor-doctest/badges/coverage.svg[Test Coverage, link="https://codeclimate.com/github/asciidoctor/asciidoctor-doctest"]
15
- image:https://codeclimate.com/github/asciidoctor/asciidoctor-doctest/badges/gpa.svg[Code Climate, link="https://codeclimate.com/github/asciidoctor/asciidoctor-doctest"]
16
- image:http://inch-ci.org/github/asciidoctor/asciidoctor-doctest.svg?branch=master[Inline docs, link="http://inch-ci.org/github/asciidoctor/asciidoctor-doctest"]
17
- image:https://badge.fury.io/rb/asciidoctor-doctest.svg[Gem Version, link="http://badge.fury.io/rb/asciidoctor-doctest"]
18
- image:https://img.shields.io/badge/yard-docs-blue.svg[Yard Docs, link="http://www.rubydoc.info/github/asciidoctor/asciidoctor-doctest/frames"]
18
+ image:https://img.shields.io/travis/{gh-name}/{gh-branch}.svg?style={badge-style}[Build Status, link="https://travis-ci.org/{gh-name}"]
19
+ image:https://img.shields.io/codeclimate/coverage/github/{gh-name}.svg?style={badge-style}[Test Coverage, link="https://codeclimate.com/github/{gh-name}"]
20
+ image:https://img.shields.io/codeclimate/github/{gh-name}.svg?style={badge-style}[Code Climate, link="https://codeclimate.com/github/{gh-name}"]
21
+ image:https://inch-ci.org/github/{gh-name}.svg?branch={gh-branch}&style={badge-style}[Inline docs, link="http://inch-ci.org/github/{gh-name}"]
22
+ image:https://img.shields.io/gem/v/{gem-name}.svg?style={badge-style}[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
23
+ image:https://img.shields.io/badge/yard-docs-blue.svg?style={badge-style}[Yard Docs, link="http://www.rubydoc.info/github/{gh-name}/frames"]
19
24
 
20
25
  DocTest is a tool for end-to-end testing of Asciidoctor _backends_ based on comparing of textual output.
21
26
 
22
27
  It provides a collection of categorized <<input-examples, input _examples_>> (documents in AsciiDoc syntax) to simplify and systematize writing tests for new backends.
23
28
  You just write or <<generate-examples, generate>> the expected output, i.e. what the backend should produce for the given input.
24
29
 
25
- image::https://cdn.rawgit.com/asciidoctor/asciidoctor-doctest/master/doc/img/doctest-diag.svg[diagram, align="center"]
30
+ image::{rawgit-base}/doc/img/doctest-diag.svg[diagram, align="center"]
26
31
 
27
32
  Each example should be focused on one use case, so when writing a new backend, you can incrementally implement new features following the reference input examples.
28
33
  However, they are not strictly isolated like unit tests.
@@ -80,14 +85,14 @@ DocTest.examples_path.unshift 'test/examples/asciidoc'
80
85
  DocTest.examples_path.unshift 'test/examples/shiny'
81
86
  ----
82
87
 
83
- . Create test file `test/templates_test.rb` and extend class link:{src-base}/test.rb[DocTest::Test]. Specify `renderer_opts` and then call `generate_tests!` macro with a specific subclass of `BaseExamplesSuite`:
88
+ . Create test file `test/templates_test.rb` and extend class link:{src-base}/test.rb[DocTest::Test]. Specify `converter_opts` and then call `generate_tests!` macro with a specific subclass of `BaseExamplesSuite`:
84
89
  +
85
90
  [source]
86
91
  ----
87
92
  require 'test_helper'
88
93
 
89
94
  class TestTemplates < DocTest::Test
90
- renderer_opts template_dirs: 'data/templates'
95
+ converter_opts template_dirs: 'data/templates'
91
96
  generate_tests! DocTest::HTML::ExamplesSuite
92
97
  end
93
98
  ----
@@ -109,7 +114,7 @@ end
109
114
 
110
115
  DocTest::GeneratorTask.new(:generate) do |task|
111
116
  task.output_suite = DocTest::HTML::ExamplesSuite.new(examples_path: 'test/examples/shiny')
112
- task.renderer_opts[:template_dirs] = 'data/templates'
117
+ task.converter_opts[:template_dirs] = 'data/templates'
113
118
  #
114
119
  # add extra input examples (optional)
115
120
  task.examples_path.unshift 'test/examples/asciidoc'
@@ -223,7 +228,7 @@ If it’s not your case, then you must overwrite it:
223
228
  [source]
224
229
  ----
225
230
  class TestShiny < DocTest::Test
226
- renderer_opts template_dirs: 'data/templates'
231
+ converter_opts template_dirs: 'data/templates'
227
232
  generate_tests! DocTest::HTML::ExamplesSuite.new(paragraph_xpath: './div/p/node()')
228
233
  end
229
234
  ----
data/Rakefile CHANGED
@@ -1,12 +1,37 @@
1
+ require 'rake/clean'
1
2
  require 'bundler/gem_tasks'
2
3
 
4
+ default_tasks = []
5
+
3
6
  begin
4
7
  require 'rspec/core/rake_task'
5
8
 
6
9
  RSpec::Core::RakeTask.new(:spec)
7
10
 
8
11
  task :test => :spec
9
- task :default => :spec
10
- rescue LoadError
11
- warn 'no rspec available'
12
+ default_tasks << :spec
13
+ rescue LoadError => e
14
+ warn "#{e.path} is not available"
15
+ end
16
+
17
+ begin
18
+ require 'cucumber/rake/task'
19
+
20
+ Cucumber::Rake::Task.new do |t|
21
+ t.cucumber_opts = ['-r features/support', '--format pretty']
22
+ end
23
+
24
+ default_tasks << :cucumber
25
+ rescue LoadError => e
26
+ warn "#{e.path} is not available"
12
27
  end
28
+
29
+ begin
30
+ require 'yard'
31
+ # options are defined in .yardopts
32
+ YARD::Rake::YardocTask.new(:yard)
33
+ rescue LoadError => e
34
+ warn "#{e.path} is not available"
35
+ end
36
+
37
+ task :default => default_tasks
data/features/README ADDED
@@ -0,0 +1 @@
1
+ This directory contains end-to-end integration tests (not acceptance tests).
@@ -0,0 +1,15 @@
1
+ require 'asciidoctor/doctest'
2
+ require 'rake/testtask'
3
+ require 'tilt'
4
+
5
+ DocTest::GeneratorTask.new(:generate) do |task|
6
+ task.output_suite = DocTest::HTML::ExamplesSuite.new(examples_path: 'examples/html')
7
+ task.examples_path = 'examples/asciidoc'
8
+ task.converter_opts[:template_dirs] = 'templates'
9
+ end
10
+
11
+ Rake::TestTask.new(:test) do |task|
12
+ task.description = 'Run tests for custom HTML backend'
13
+ task.pattern = 'test/html_test.rb'
14
+ task.libs << 'test'
15
+ end
@@ -0,0 +1,12 @@
1
+ // .with_id_and_role
2
+ [quote, id="parking", role="startrek"]
3
+ Everybody remember where we parked.
4
+
5
+ // .with_title
6
+ .After landing the cloaked Klingon bird of prey in Golden Gate park:
7
+ [quote]
8
+ Everybody remember where we parked.
9
+
10
+ // .with_attribution
11
+ [quote, Albert Einstein]
12
+ A person who never made a mistake _never_ tried anything new.
@@ -0,0 +1,4 @@
1
+ // .title_with_author
2
+ // This example should fail.
3
+ = The Dangerous and Thrilling Documentation Chronicles
4
+ Kismet Rainbow Chameleon <kismet@asciidoctor.org>
@@ -0,0 +1,2 @@
1
+ // .emphasis
2
+ _chunky bacon_
@@ -0,0 +1,26 @@
1
+ <!-- .basic
2
+ Doesn't exist in input examples.
3
+ -->
4
+ <div class="quoteblock">
5
+ <blockquote>Four score and seven years ago our fathers brought forth
6
+ on this continent a new nation&#8230;&#8203;</blockquote>
7
+ </div>
8
+
9
+ <!-- .with_id_and_role
10
+ Correct example.
11
+ -->
12
+ <div id="parking"
13
+ class="quoteblock startrek">
14
+ <blockquote>
15
+ Everybody remember
16
+ where we parked.
17
+ </blockquote>
18
+ </div>
19
+
20
+ <!-- .with_attribution
21
+ Failing example.
22
+ -->
23
+ <div class="quoteblock">
24
+ <blockquote>A person who never made a mistake <em>never</em> tried anything new.</blockquote>
25
+ <span>Albert Einstein</span>
26
+ </div>
@@ -0,0 +1,7 @@
1
+ <!-- .title_with_author
2
+ :include: .//body/div[@id="header"]
3
+ -->
4
+ <div id="header">
5
+ <h1>The Dangerous and Thrilling Documentation Chronicles</h1>
6
+ <div id="author">Kismet Rainbow Chameleon</div>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ *{:tag=>(title.nil_or_empty? ? 'div' : 'section'), :id=>id, :class=>['quoteblock', *role]}
2
+ - unless title.nil_or_empty?
3
+ h6 =captioned_title
4
+ blockquote =content
5
+ - if attr? :attribution
6
+ .attribution
7
+ | &#8212; #{attr :attribution}
@@ -0,0 +1,13 @@
1
+ doctype 5
2
+ html lang=(attr :lang, 'en' unless attr? :nolang)
3
+ head
4
+ meta charset='UTF-8'
5
+ title=((doctitle sanitize: true) || (attr 'untitled-label'))
6
+ body
7
+ - unless noheader && notitle
8
+ #header
9
+ h1 =header.title
10
+ - if attr? :author
11
+ .details
12
+ span#author =(attr :author)
13
+ #content =content
@@ -0,0 +1,3 @@
1
+ - unless notitle || !has_header?
2
+ h1 id=id =header.title
3
+ =content
@@ -0,0 +1,8 @@
1
+ - case type
2
+ - when :emphasis
3
+ em class=role =text
4
+ - when :strong
5
+ strong class=role =text
6
+ - else
7
+ .span class=role
8
+ =text
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ class TestHtml < DocTest::Test
4
+ converter_opts template_dirs: 'templates'
5
+ generate_tests! DocTest::HTML::ExamplesSuite
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'asciidoctor/doctest'
2
+ require 'minitest/autorun'
3
+ require 'tilt'
4
+
5
+ DocTest.examples_path = ['examples/html', 'examples/asciidoc']
@@ -0,0 +1,171 @@
1
+ Feature: Generating output examples for a custom HTML backend
2
+
3
+ Background:
4
+ Given I do have a template-based HTML backend with DocTest
5
+
6
+ Scenario: Generate missing output examples
7
+ When I run `bundle exec rake generate`
8
+ Then the output should contain:
9
+ """
10
+ Generate testing examples *:*.
11
+ --> Unchanged block_quote:with_id_and_role
12
+ --> Generating block_quote:with_title
13
+ --> Skipping block_quote:with_attribution
14
+ --> Unknown block_quote:basic, doesn't exist in input examples!
15
+ --> Skipping document:title_with_author
16
+ --> Generating inline_quoted:emphasis
17
+
18
+ """
19
+ And the file "examples/html/block_quote.html" should contain exactly:
20
+ """
21
+ <!-- .basic
22
+ Doesn't exist in input examples.
23
+ -->
24
+ <div class="quoteblock">
25
+ <blockquote>Four score and seven years ago our fathers brought forth
26
+ on this continent a new nation&#8230;&#8203;</blockquote>
27
+ </div>
28
+
29
+ <!-- .with_id_and_role
30
+ Correct example.
31
+ -->
32
+ <div id="parking"
33
+ class="quoteblock startrek">
34
+ <blockquote>
35
+ Everybody remember
36
+ where we parked.
37
+ </blockquote>
38
+ </div>
39
+
40
+ <!-- .with_attribution
41
+ Failing example.
42
+ -->
43
+ <div class="quoteblock">
44
+ <blockquote>A person who never made a mistake <em>never</em> tried anything new.</blockquote>
45
+ <span>Albert Einstein</span>
46
+ </div>
47
+
48
+ <!-- .with_title -->
49
+ <section class="quoteblock"><h6>After landing the cloaked Klingon bird of prey in Golden Gate park:</h6>
50
+ <blockquote>Everybody remember where we parked.</blockquote></section>
51
+
52
+ """
53
+ And the file "examples/html/document.html" should contain exactly:
54
+ """
55
+ <!-- .title_with_author
56
+ :include: .//body/div[@id="header"]
57
+ -->
58
+ <div id="header">
59
+ <h1>The Dangerous and Thrilling Documentation Chronicles</h1>
60
+ <div id="author">Kismet Rainbow Chameleon</div>
61
+ </div>
62
+
63
+ """
64
+ And the file "examples/html/inline_quoted.html" should contain exactly:
65
+ """
66
+ <!-- .emphasis -->
67
+ <em>chunky bacon</em>
68
+
69
+ """
70
+
71
+ Scenario: Regenerate all outdated output examples
72
+ When I run `bundle exec rake generate FORCE=yes`
73
+ Then the output should contain:
74
+ """
75
+ Generate testing examples *:*.
76
+ --> Unchanged block_quote:with_id_and_role
77
+ --> Generating block_quote:with_title
78
+ --> Rewriting block_quote:with_attribution
79
+ --> Unknown block_quote:basic, doesn't exist in input examples!
80
+ --> Rewriting document:title_with_author
81
+ --> Generating inline_quoted:emphasis
82
+
83
+ """
84
+ And the file "examples/html/block_quote.html" should contain exactly:
85
+ """
86
+ <!-- .basic
87
+ Doesn't exist in input examples.
88
+ -->
89
+ <div class="quoteblock">
90
+ <blockquote>Four score and seven years ago our fathers brought forth
91
+ on this continent a new nation&#8230;&#8203;</blockquote>
92
+ </div>
93
+
94
+ <!-- .with_id_and_role
95
+ Correct example.
96
+ -->
97
+ <div id="parking"
98
+ class="quoteblock startrek">
99
+ <blockquote>
100
+ Everybody remember
101
+ where we parked.
102
+ </blockquote>
103
+ </div>
104
+
105
+ <!-- .with_attribution
106
+ Failing example.
107
+ -->
108
+ <div class="quoteblock">
109
+ <blockquote>A person who never made a mistake
110
+ <em>never</em>
111
+ tried anything new.</blockquote>
112
+ <div class="attribution">— Albert Einstein</div>
113
+ </div>
114
+
115
+ <!-- .with_title -->
116
+ <section class="quoteblock"><h6>After landing the cloaked Klingon bird of prey in Golden Gate park:</h6>
117
+ <blockquote>Everybody remember where we parked.</blockquote></section>
118
+
119
+ """
120
+ And the file "examples/html/document.html" should contain exactly:
121
+ """
122
+ <!-- .title_with_author
123
+ :include: .//body/div[@id="header"]
124
+ -->
125
+ <div id="header">
126
+ <h1>The Dangerous and Thrilling Documentation Chronicles</h1>
127
+ <div class="details"><span id="author">Kismet Rainbow Chameleon</span></div>
128
+ </div>
129
+
130
+ """
131
+
132
+ Scenario: Regenerate outdated output examples specified by filter
133
+ When I run `bundle exec rake generate PATTERN="*:*attribution" FORCE=yes`
134
+ Then the output should contain:
135
+ """
136
+ Generate testing examples *:*attribution.
137
+ --> Rewriting block_quote:with_attribution
138
+
139
+ """
140
+ And the file "examples/html/block_quote.html" should contain exactly:
141
+ """
142
+ <!-- .basic
143
+ Doesn't exist in input examples.
144
+ -->
145
+ <div class="quoteblock">
146
+ <blockquote>Four score and seven years ago our fathers brought forth
147
+ on this continent a new nation&#8230;&#8203;</blockquote>
148
+ </div>
149
+
150
+ <!-- .with_id_and_role
151
+ Correct example.
152
+ -->
153
+ <div id="parking"
154
+ class="quoteblock startrek">
155
+ <blockquote>
156
+ Everybody remember
157
+ where we parked.
158
+ </blockquote>
159
+ </div>
160
+
161
+ <!-- .with_attribution
162
+ Failing example.
163
+ -->
164
+ <div class="quoteblock">
165
+ <blockquote>A person who never made a mistake
166
+ <em>never</em>
167
+ tried anything new.</blockquote>
168
+ <div class="attribution">— Albert Einstein</div>
169
+ </div>
170
+
171
+ """