asciidoctor-doctest 1.5.2.0 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.adoc +48 -68
  4. data/features/fixtures/html-slim/Rakefile +5 -11
  5. data/features/generator_html.feature +6 -6
  6. data/features/test_html.feature +70 -28
  7. data/lib/asciidoctor/doctest.rb +11 -14
  8. data/lib/asciidoctor/doctest/asciidoc_converter.rb +85 -0
  9. data/lib/asciidoctor/doctest/{base_example.rb → example.rb} +6 -27
  10. data/lib/asciidoctor/doctest/factory.rb +36 -0
  11. data/lib/asciidoctor/doctest/generator.rb +30 -23
  12. data/lib/asciidoctor/doctest/html/converter.rb +64 -0
  13. data/lib/asciidoctor/doctest/{html/normalizer.rb → html_normalizer.rb} +4 -4
  14. data/lib/asciidoctor/doctest/io.rb +14 -0
  15. data/lib/asciidoctor/doctest/{asciidoc/examples_suite.rb → io/asciidoc.rb} +4 -8
  16. data/lib/asciidoctor/doctest/{base_examples_suite.rb → io/base.rb} +28 -46
  17. data/lib/asciidoctor/doctest/io/xml.rb +69 -0
  18. data/lib/asciidoctor/doctest/no_fallback_template_converter.rb +42 -0
  19. data/lib/asciidoctor/doctest/rake_tasks.rb +229 -0
  20. data/lib/asciidoctor/doctest/test_reporter.rb +110 -0
  21. data/lib/asciidoctor/doctest/tester.rb +134 -0
  22. data/lib/asciidoctor/doctest/version.rb +1 -1
  23. data/spec/asciidoc_converter_spec.rb +64 -0
  24. data/spec/{base_example_spec.rb → example_spec.rb} +4 -5
  25. data/spec/factory_spec.rb +46 -0
  26. data/spec/html/converter_spec.rb +95 -0
  27. data/spec/{html/normalizer_spec.rb → html_normalizer_spec.rb} +1 -1
  28. data/spec/{asciidoc/examples_suite_spec.rb → io/asciidoc_spec.rb} +3 -8
  29. data/spec/{html/examples_suite_spec.rb → io/xml_spec.rb} +3 -106
  30. data/spec/no_fallback_template_converter_spec.rb +38 -0
  31. data/spec/shared_examples/{base_examples_suite.rb → base_examples.rb} +25 -28
  32. data/spec/spec_helper.rb +4 -0
  33. data/spec/tester_spec.rb +153 -0
  34. metadata +52 -59
  35. data/features/fixtures/html-slim/test/html_test.rb +0 -6
  36. data/features/fixtures/html-slim/test/test_helper.rb +0 -5
  37. data/lib/asciidoctor/doctest/asciidoc_renderer.rb +0 -111
  38. data/lib/asciidoctor/doctest/generator_task.rb +0 -115
  39. data/lib/asciidoctor/doctest/html/example.rb +0 -21
  40. data/lib/asciidoctor/doctest/html/examples_suite.rb +0 -118
  41. data/lib/asciidoctor/doctest/test.rb +0 -125
  42. data/spec/asciidoc_renderer_spec.rb +0 -103
  43. data/spec/test_spec.rb +0 -164
@@ -1,103 +0,0 @@
1
- require 'fileutils'
2
-
3
- describe DocTest::AsciidocRenderer do
4
-
5
- subject { described_class }
6
-
7
- it { is_expected.to have_method :convert, :render }
8
-
9
-
10
- describe '#initialize' do
11
-
12
- context 'with defaults' do
13
- subject { described_class.new }
14
- it { is_expected.to have_attributes backend_name: nil, converter: nil, template_dirs: nil }
15
- end
16
-
17
- context 'with backend_name' do
18
- subject { described_class.new(backend_name: 'html5') }
19
- it { is_expected.to have_attributes backend_name: 'html5' }
20
-
21
- context 'empty string' do
22
- subject { described_class.new(backend_name: '') }
23
- it { is_expected.to have_attributes backend_name: nil }
24
- end
25
- end
26
-
27
- context 'with template_dirs' do
28
- include FakeFS::SpecHelpers
29
-
30
- subject { described_class.new(template_dirs: template_dirs) }
31
- let(:template_dirs) { ['/tmp/html5'] }
32
-
33
- before { FileUtils.mkpath template_dirs[0] }
34
-
35
- context 'that exists' do
36
- it do
37
- is_expected.to have_attributes(
38
- template_dirs: template_dirs,
39
- converter: DocTest::NoFallbackTemplateConverter
40
- )
41
- end
42
-
43
- context 'and templates_fallback = true' do
44
- subject { described_class.new(template_dirs: template_dirs, templates_fallback: true) }
45
- it { is_expected.to have_attributes template_dirs: template_dirs, converter: nil }
46
- end
47
-
48
- context 'and custom converter' do
49
- subject { described_class.new(template_dirs: template_dirs, converter: converter) }
50
- let(:converter) { Asciidoctor::Converter::TemplateConverter }
51
-
52
- it { is_expected.to have_attributes template_dirs: template_dirs, converter: converter }
53
- end
54
- end
55
-
56
- context "that doesn't exist" do
57
- let(:template_dirs) { ['/tmp/html5', '/tmp/revealjs'] }
58
-
59
- it { expect { subject }.to raise_error ArgumentError }
60
- end
61
- end
62
- end
63
- end
64
-
65
-
66
- describe DocTest::NoFallbackTemplateConverter do
67
-
68
- subject(:delegator) { described_class.new('html5', template_dirs: ['/tmp/html5']) }
69
-
70
- describe '#convert' do
71
-
72
- let(:converter) { delegator.__getobj__ }
73
- let(:node) { double('Node', node_name: 'block_foo') }
74
-
75
- before do
76
- expect(converter).to receive(:handles?).with('block_foo').and_return(handles)
77
- end
78
-
79
- context 'when template is not found' do
80
- let(:handles) { false }
81
-
82
- it 'returns a not found marker instead of converted node' do
83
- expect(converter).to_not receive(:convert)
84
- expect(delegator.convert node).to eq described_class::NOT_FOUND_MARKER
85
- end
86
-
87
- it 'prints a warning on stderr' do
88
- expect { delegator.convert node }.to output(/Could not find a custom template/i).to_stderr
89
- end
90
- end
91
-
92
- context 'when template is found' do
93
- let(:handles) { true }
94
-
95
- it 'delegates to the original #convert and returns result' do
96
- expect(converter).to receive(:convert)
97
- .with(node, 'block_foo', {}).and_return('allons-y!')
98
-
99
- expect(delegator.convert node).to eq 'allons-y!'
100
- end
101
- end
102
- end
103
- end
data/spec/test_spec.rb DELETED
@@ -1,164 +0,0 @@
1
- describe DocTest::Test do
2
-
3
- subject(:test_class) { Class.new described_class }
4
-
5
- let(:renderer) { double 'Renderer' }
6
- let(:input_suite) { double 'ExamplesSuite' }
7
- let(:output_suite) { double 'ExamplesSuite' }
8
-
9
- before do
10
- test_class.instance_variable_set(:@renderer, renderer)
11
- end
12
-
13
- it { is_expected.to have_method :input_suite, :output_suite, :renderer }
14
-
15
-
16
- describe '.define_test' do
17
- before { test_class.define_test('dummy') { 42 } }
18
-
19
- it 'defines method with the given name' do
20
- is_expected.to have_method :dummy
21
- expect(test_class.new('dummy').send(:dummy)).to eq 42
22
- end
23
-
24
- it "adds the method's name to runnable_methods" do
25
- expect(test_class.runnable_methods).to eq ['dummy']
26
- end
27
- end
28
-
29
-
30
- describe '.runnable_methods' do
31
- subject { test_class.runnable_methods }
32
-
33
- context 'when no test defined yet' do
34
- it { is_expected.to be_empty }
35
- end
36
-
37
- context 'when some test is defined using test macro' do
38
- it 'returns array with the test method name' do
39
- test_class.define_test('dummy') { 42 }
40
- is_expected.to eq ['dummy']
41
- end
42
- end
43
-
44
- context 'when any method named /test_.*/ exists' do
45
- it 'returns array with the method name' do
46
- test_class.send(:define_method, :test_me) { 42 }
47
- is_expected.to eq ['test_me']
48
- end
49
- end
50
- end
51
-
52
-
53
- describe '.generate_tests!' do
54
-
55
- let :examples do
56
- [
57
- [ (create_example 'bl:basic', content: '_meh_'),
58
- (create_example 'bl:basic', content: '<i>meh</i>') ],
59
- [ (create_example 'bl:noinput'),
60
- (create_example 'bl:noinput') ],
61
- [ (create_example 'bl:nooutput', content: '_meh_'),
62
- (create_example 'bl:nooutput') ]
63
- ]
64
- end
65
-
66
- before do
67
- expect(input_suite).to receive(:pair_with)
68
- .with(output_suite).and_return(examples)
69
- test_class.generate_tests! output_suite, input_suite
70
- end
71
-
72
- context 'when both input and output examples are present' do
73
- subject(:test_inst) { test_class.new('bl:basic') }
74
-
75
- it 'defines test method that calls method :test_example'do
76
- is_expected.to receive(:test_example)
77
- test_inst.send(:'bl:basic')
78
- end
79
- end
80
-
81
- context 'when input example is missing' do
82
- it "doesn't define a test method for it" do
83
- is_expected.to_not have_method :'bl:noinput'
84
- end
85
- end
86
-
87
- context 'when output example is missing' do
88
- subject { test_class.new('bl:nooutput') }
89
-
90
- it 'defines test method with "skip"' do
91
- expect { subject.send(:'bl:nooutput') }.to raise_error Minitest::Skip
92
- end
93
- end
94
- end
95
-
96
-
97
- describe '#location' do
98
- subject { test_class.new('block_ulist:basic').location }
99
-
100
- # test_class is anonymous, so we must give it some name
101
- before { DummyTest = test_class unless defined? DummyTest }
102
-
103
- it 'returns formatted example name' do
104
- is_expected.to eq 'DummyTest :: block_ulist : basic'
105
- end
106
- end
107
-
108
-
109
- describe '#test_example' do
110
- subject(:test_inst) { test_class.new('bl:basic') }
111
-
112
- let(:input_exmpl) { create_example 'bl:basic', content: '_meh_' }
113
- let(:output_exmpl) { create_example 'bl:basic', content: '<i>meh</i>', opts: {foo: 42} }
114
- let(:test_example!) { test_inst.test_example output_exmpl, input_exmpl }
115
-
116
- before do
117
- allow(input_suite).to receive(:pair_with)
118
- .with(output_suite)
119
- .and_return([])
120
-
121
- expect(output_suite).to receive(:convert_example)
122
- .with(input_exmpl, output_exmpl.opts, renderer)
123
- .and_return(actual_exmpl)
124
-
125
- test_class.generate_tests! output_suite, input_suite
126
- end
127
-
128
- context 'when examples are equivalent' do
129
- let(:actual_exmpl) { output_exmpl.dup }
130
-
131
- it 'no error is thrown' do
132
- expect { test_example! }.not_to raise_error
133
- end
134
- end
135
-
136
- context 'when examples are not equivalent' do
137
- let(:input_exmpl) { create_example 'bl:basic', content: '_meh_', desc: 'yada yada' }
138
- let(:actual_exmpl) { output_exmpl.dup.tap { |o| o.content = '<em>meh</em>' } }
139
-
140
- it 'throws Minitest::Assertion error' do
141
- expect { test_example! }.to raise_error Minitest::Assertion
142
- end
143
-
144
- context 'and input example has desc:' do
145
- it 'throws error which message starts with the desc' do
146
- expect { test_example! }.to raise_error(/^yada yada.*/)
147
- end
148
- end
149
-
150
- context 'and both input and output examples have desc:' do
151
- let(:output_exmpl) { create_example 'bl:basic', content: '<i>meh</i>', desc: 'Yoda' }
152
-
153
- it "throws error which message starts with the output's example desc" do
154
- expect { test_example! }.to raise_error(/^Yoda.*/)
155
- end
156
- end
157
- end
158
- end
159
-
160
-
161
- def create_example(*args)
162
- DocTest::BaseExample.new(*args)
163
- end
164
- end