-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
examples_suite_spec.rb
157 lines (121 loc) · 3.64 KB
/
examples_suite_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
describe DocTest::Latex::ExamplesSuite do
extend Forwardable
it_should_behave_like DocTest::BaseExamplesSuite
def_delegator :suite, :create_example
subject(:suite) { described_class.new }
describe '#initialize' do
it 'uses ".tex" as default file_ext' do
expect(suite.file_ext).to eq '.tex'
end
end
describe 'parsing/serialization:' do
context 'one example' do
shared_examples :example do
let(:parsed) { suite.parse input, 's' }
let(:serialized) { suite.serialize output }
it { expect(parsed).to have(1).items }
it 'returns an array with parsed example object' do
expect(parsed.first).to eql output
end
it 'returns a serialized example as string' do
expect(serialized).to eql input
end
end
context 'with name only' do
let(:input) { "% .basic\n" }
let(:output) { create_example 's:basic' }
include_examples :example
end
context 'with multiline content' do
let :content do
<<-EOF.strip_heredoc
Paragraphs don't require
any special markup.
To begin a new one, separate it by blank line.
EOF
end
let(:input) { "% .multiline\n#{content}" }
let(:output) { create_example 's:multiline', content: content.chomp }
include_examples :example
end
context 'with description' do
let :input do
<<-EOF.strip_heredoc
% .strong
% This is a description,
% see?
\\textbf{allons-y!}
EOF
end
let :output do
create_example 's:strong', content: '\\textbf{allons-y!}',
desc: "This is a description,\nsee?"
end
include_examples :example
end
context 'with options' do
let :input do
<<-EOF.strip_heredoc
% .basic
% :exclude: .//code
% :exclude: .//section
% :include: ./p/node()
dummy
EOF
end
let :output do
create_example 's:basic', content: 'dummy', opts: {
exclude: ['.//code', './/section'],
include: ['./p/node()']
}
end
include_examples :example
end
context 'with boolean option' do
let :input do
<<-EOF.strip_heredoc
% .basic
% :header_footer:
EOF
end
let :output do
create_example 's:basic', opts: { header_footer: true }
end
include_examples :example
end
context 'with description and options' do
let :input do
<<-EOF.strip_heredoc
% .basic
% This is a description.
% :exclude: .//code
% :header_footer:
EOF
end
let :output do
create_example 's:basic', desc: 'This is a description.', opts: {
exclude: ['.//code'],
header_footer: true
}
end
include_examples :example
end
end
context 'multiple examples' do
let :input do
<<-EOF.strip_heredoc
% .basic
http://asciidoctor.org
% .xref
Refer to <<section-a>>.
EOF
end
subject(:parsed) { suite.parse input, 's' }
it { is_expected.to have(2).items }
it 'returns an array with parsed Example objects' do
expect(parsed[0]).to eql create_example('s:basic', content: 'http://asciidoctor.org')
expect(parsed[1]).to eql create_example('s:xref', content: 'Refer to <<section-a>>.')
end
end
end
end