metanorma-iec 2.1.11 → 2.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/iec/iec.international-standard.xsl +274 -100
  3. data/lib/isodoc/iec/presentation_xml_convert.rb +8 -6
  4. data/lib/metanorma/iec/biblio.rng +5 -0
  5. data/lib/metanorma/iec/iec_intro_en.xml +11 -12
  6. data/lib/metanorma/iec/iec_intro_fr.xml +11 -11
  7. data/lib/metanorma/iec/isodoc.rng +46 -12
  8. data/lib/metanorma/iec/version.rb +1 -1
  9. data/metanorma-iec.gemspec +5 -2
  10. metadata +4 -36
  11. data/.github/workflows/automerge.yml +0 -31
  12. data/.github/workflows/rake.yml +0 -15
  13. data/.github/workflows/release.yml +0 -24
  14. data/Rakefile +0 -8
  15. data/bin/rspec +0 -18
  16. data/spec/assets/header.html +0 -7
  17. data/spec/assets/html.css +0 -2
  18. data/spec/assets/iso.xml +0 -71
  19. data/spec/assets/rice_image1.png +0 -0
  20. data/spec/assets/word.css +0 -2
  21. data/spec/assets/wordintro.html +0 -4
  22. data/spec/assets/xref_error.adoc +0 -7
  23. data/spec/isodoc/blocks_spec.rb +0 -200
  24. data/spec/isodoc/i18n_spec.rb +0 -607
  25. data/spec/isodoc/iev_spec.rb +0 -888
  26. data/spec/isodoc/inline_spec.rb +0 -256
  27. data/spec/isodoc/iso_spec.rb +0 -211
  28. data/spec/isodoc/metadata_spec.rb +0 -251
  29. data/spec/isodoc/postproc_spec.rb +0 -303
  30. data/spec/isodoc/ref_spec.rb +0 -335
  31. data/spec/isodoc/section_spec.rb +0 -566
  32. data/spec/isodoc/terms_spec.rb +0 -192
  33. data/spec/metanorma/base_spec.rb +0 -1041
  34. data/spec/metanorma/blocks_spec.rb +0 -470
  35. data/spec/metanorma/cleanup_spec.rb +0 -372
  36. data/spec/metanorma/iev_spec.rb +0 -254
  37. data/spec/metanorma/inline_spec.rb +0 -145
  38. data/spec/metanorma/lists_spec.rb +0 -194
  39. data/spec/metanorma/processor_spec.rb +0 -171
  40. data/spec/metanorma/section_spec.rb +0 -348
  41. data/spec/metanorma/validate_spec.rb +0 -56
  42. data/spec/spec_helper.rb +0 -305
@@ -1,348 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Metanorma::Iec do
4
- before(:all) do
5
- @blank_hdr = blank_hdr_gen
6
- end
7
-
8
- it "processes sections" do
9
- input = <<~INPUT
10
- #{ASCIIDOC_BLANK_HDR}
11
- .Foreword
12
-
13
- Text
14
-
15
- == Introduction
16
-
17
- === Introduction Subsection
18
-
19
- == Scope
20
-
21
- Text
22
-
23
- == Normative References
24
-
25
- == Terms and Definitions
26
-
27
- === Term1
28
-
29
- == Terms, Definitions, Symbols and Abbreviated Terms
30
-
31
- === Normal Terms
32
-
33
- ==== Term2
34
-
35
- === Symbols and Abbreviated Terms
36
-
37
- == Symbols and Abbreviated Terms
38
-
39
- == Clause 4
40
-
41
- === Introduction
42
-
43
- === Clause 4.2
44
-
45
- == Terms and Definitions
46
-
47
- [appendix]
48
- == Annex
49
-
50
- === Annex A.1
51
-
52
- [%appendix]
53
- === Appendix 1
54
-
55
- == Bibliography
56
-
57
- === Bibliography Subsection
58
- INPUT
59
- output = <<~OUTPUT
60
- #{@blank_hdr}
61
- <preface><foreword id="_" obligation="informative">
62
- <title>FOREWORD</title>
63
- <p id="_">Text</p>
64
- </foreword><introduction id="_" obligation="informative">
65
- <title>INTRODUCTION</title><clause id="_" inline-header="false" obligation="informative">
66
- <title>Introduction Subsection</title>
67
- </clause>
68
- </introduction></preface><sections>
69
- <clause id="_" obligation="normative" type="scope" inline-header='false'>
70
- <title>Scope</title>
71
- <p id="_">Text</p>
72
- </clause>
73
-
74
- <terms id="_" obligation="normative">
75
- <title>Terms and definitions</title>
76
- <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
77
- #{TERMS_BOILERPLATE}
78
- <term id="term-Term1">
79
- <preferred><expression><name>Term1</name></expression></preferred>
80
- </term>
81
- </terms>
82
- <clause id="_" obligation="normative"><title>Terms, definitions, symbols and abbreviated terms</title><terms id="_" obligation="normative">
83
- <title>Normal Terms</title>
84
- <term id="term-Term2">
85
- <preferred><expression><name>Term2</name></expression></preferred>
86
- </term>
87
- </terms>
88
- <definitions id="_" obligation="normative"><title>Symbols and abbreviated terms</title></definitions></clause>
89
- <definitions id="_" obligation="normative"><title>Symbols and abbreviated terms</title></definitions>
90
- <clause id="_" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="_" inline-header="false" obligation="normative">
91
- <title>Introduction</title>
92
- </clause>
93
- <clause id="_" inline-header="false" obligation="normative">
94
- <title>Clause 4.2</title>
95
- </clause></clause>
96
- <clause id="_" inline-header="false" obligation="normative">
97
- <title>Terms and Definitions</title>
98
- </clause>
99
-
100
-
101
- </sections><annex id="_" inline-header="false" obligation="normative">
102
- <title>Annex</title>
103
- <clause id="_" inline-header="false" obligation="normative">
104
- <title>Annex A.1</title>
105
- </clause>
106
- <appendix id="_" inline-header="false" obligation="normative">
107
- <title>Appendix 1</title>
108
- </appendix></annex><bibliography><references id="_" obligation="informative" normative="true">
109
- <title>Normative references</title><p id="_">There are no normative references in this document.</p>
110
- </references><clause id="_" obligation="informative">
111
- <title>Bibliography</title>
112
- <references id="_" obligation="informative" normative="false">
113
- <title>Bibliography Subsection</title>
114
- </references>
115
- </clause>
116
- </bibliography>
117
- </iec-standard>
118
- OUTPUT
119
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
120
- .to be_equivalent_to xmlpp(output)
121
- end
122
-
123
- it "processes sections with title attributes" do
124
- input = <<~INPUT
125
- #{ASCIIDOC_BLANK_HDR}
126
- .Foreword
127
-
128
- Text
129
-
130
- [heading=introduction]
131
- == Εισαγωγή
132
-
133
- === Introduction Subsection
134
-
135
- [heading=scope]
136
- == Σκοπός
137
-
138
- Text
139
-
140
- [heading=normative references]
141
- == Κανονιστικές Παραπομπές
142
-
143
- [heading=terms and definitions]
144
- == Όροι και Ορισμοί
145
-
146
- === Term1
147
-
148
- [heading="terms, definitions, symbols and abbreviated terms"]
149
- == Όροι, Ορισμοί, Σύμβολα και Συντομογραφίες
150
-
151
- === Normal Terms
152
-
153
- ==== Term2
154
-
155
- [heading=symbols and abbreviated terms]
156
- === Σύμβολα και Συντομογραφίες
157
-
158
- [heading=symbols and abbreviated terms]
159
- == Σύμβολα και Συντομογραφίες
160
-
161
- == Clause 4
162
-
163
- === Introduction
164
-
165
- === Clause 4.2
166
-
167
- [appendix]
168
- == Annex
169
-
170
- === Annex A.1
171
-
172
- [%appendix]
173
- === Appendx 1
174
-
175
- [heading=bibliography]
176
- == Βιβλιογραφία
177
-
178
- === Bibliography Subsection
179
- INPUT
180
- output = <<~OUTPUT
181
- #{@blank_hdr}
182
- <preface>
183
- <foreword id="_" obligation="informative">
184
- <title>FOREWORD</title>
185
- <p id="_">Text</p>
186
- </foreword>
187
- <introduction id="_" obligation="informative">
188
- <title>INTRODUCTION</title><clause id="_" inline-header="false" obligation="informative">
189
- <title>Introduction Subsection</title>
190
- </clause>
191
- </introduction>
192
- </preface>
193
- <sections>
194
- <clause id="_" obligation="normative" type="scope" inline-header='false'>
195
- <title>Scope</title>
196
- <p id="_">Text</p>
197
- </clause>
198
- <terms id="_" obligation="normative">
199
- <title>Terms and definitions</title>
200
- <p id="_">For the purposes of this document, the following terms and definitions apply.</p>
201
- #{TERMS_BOILERPLATE}
202
- <term id="term-Term1">
203
- <preferred><expression><name>Term1</name></expression></preferred>
204
- </term>
205
- </terms>
206
- <clause id='_' obligation='normative'>
207
- <title>Terms, definitions, symbols and abbreviated terms</title>
208
- <terms id='_' obligation='normative'>
209
- <title>Normal Terms</title>
210
- <term id='term-Term2'>
211
- <preferred><expression><name>Term2</name></expression></preferred>
212
- </term>
213
- </terms>
214
- <definitions id='_' obligation="normative">
215
- <title>Symbols and abbreviated terms</title>
216
- </definitions>
217
- </clause>
218
- <definitions id='_' obligation="normative">
219
- <title>Symbols and abbreviated terms</title>
220
- </definitions>
221
- <clause id='_' inline-header='false' obligation='normative'>
222
- <title>Clause 4</title>
223
- <clause id='_' inline-header='false' obligation='normative'>
224
- <title>Introduction</title>
225
- </clause>
226
- <clause id='_' inline-header='false' obligation='normative'>
227
- <title>Clause 4.2</title>
228
- </clause>
229
- </clause>
230
- </sections>
231
- <annex id='_' inline-header='false' obligation='normative'>
232
- <title>Annex</title>
233
- <clause id='_' inline-header='false' obligation='normative'>
234
- <title>Annex A.1</title>
235
- </clause>
236
- <appendix id='_' inline-header='false' obligation='normative'>
237
- <title>Appendx 1</title>
238
- </appendix>
239
- </annex>
240
- <bibliography>
241
- <references id='_' obligation='informative' normative="true">
242
- <title>Normative references</title>
243
- <p id="_">There are no normative references in this document.</p>
244
- </references>
245
- <clause id='_' obligation='informative'>
246
- <title>Bibliography</title>
247
- <references id='_' obligation='informative' normative="false">
248
- <title>Bibliography Subsection</title>
249
- </references>
250
- </clause>
251
- </bibliography>
252
- </iec-standard>
253
- OUTPUT
254
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
255
- .to be_equivalent_to xmlpp(output)
256
- end
257
-
258
- it "processes section obligations" do
259
- input = <<~INPUT
260
- #{ASCIIDOC_BLANK_HDR}
261
- [obligation=informative]
262
- == Clause 1
263
-
264
- === Clause 1a
265
-
266
- [obligation=normative]
267
- == Clause 2
268
-
269
- [appendix,obligation=informative]
270
- == Annex
271
- INPUT
272
- output = <<~OUTPUT
273
- #{@blank_hdr}
274
- <sections><clause id="_" inline-header="false" obligation="informative">
275
- <title>Clause 1</title>
276
- <clause id="_" inline-header="false" obligation="informative">
277
- <title>Clause 1a</title>
278
- </clause>
279
- </clause>
280
- <clause id="_" inline-header="false" obligation="normative">
281
- <title>Clause 2</title>
282
- </clause>
283
- </sections><annex id="_" inline-header="false" obligation="informative">
284
- <title>Annex</title>
285
- </annex>
286
- </iec-standard>
287
- OUTPUT
288
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
289
- .to be_equivalent_to xmlpp(output)
290
- end
291
-
292
- it "processes inline headers" do
293
- input = <<~INPUT
294
- #{ASCIIDOC_BLANK_HDR}
295
- == Clause 1
296
-
297
- [%inline-header]
298
- === Clause 1a
299
-
300
- [appendix]
301
- == Annex A
302
-
303
- [%inline-header]
304
- === Clause Aa
305
- INPUT
306
- output = <<~OUTPUT
307
- #{@blank_hdr}
308
- <sections><clause id="_" inline-header="false" obligation="normative">
309
- <title>Clause 1</title>
310
- <clause id="_" inline-header="true" obligation="normative">
311
- <title>Clause 1a</title>
312
- </clause>
313
- </clause>
314
- </sections><annex id="_" inline-header="false" obligation="normative">
315
- <title>Annex A</title>
316
- <clause id="_" inline-header="true" obligation="normative">
317
- <title>Clause Aa</title>
318
- </clause>
319
- </annex>
320
- </iec-standard>
321
- OUTPUT
322
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
323
- .to be_equivalent_to xmlpp(output)
324
- end
325
-
326
- it "processes blank headers" do
327
- input = <<~INPUT
328
- #{ASCIIDOC_BLANK_HDR}
329
- == Clause 1
330
-
331
- === {blank}
332
-
333
- INPUT
334
- output = <<~OUTPUT
335
- #{@blank_hdr}
336
- <sections>
337
- <clause id="_" inline-header="false" obligation="normative">
338
- <title>Clause 1</title>
339
- <clause id="_" inline-header="false" obligation="normative">
340
- </clause>
341
- </clause>
342
- </sections>
343
- </iec-standard>
344
- OUTPUT
345
- expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
346
- .to be_equivalent_to xmlpp(output)
347
- end
348
- end
@@ -1,56 +0,0 @@
1
- require "spec_helper"
2
- require "fileutils"
3
-
4
- RSpec.describe Metanorma::Iec do
5
- context "when xref_error.adoc compilation" do
6
- around do |example|
7
- FileUtils.rm_f "spec/assets/xref_error.err"
8
- example.run
9
- Dir["spec/assets/xref_error*"].each do |file|
10
- next if file.match?(/adoc$/)
11
-
12
- FileUtils.rm_f(file)
13
- end
14
- end
15
-
16
- it "generates error file" do
17
- expect do
18
- mock_pdf
19
- Metanorma::Compile
20
- .new
21
- .compile("spec/assets/xref_error.adoc", type: "iec", no_install_fonts: true)
22
- end.to(change { File.exist?("spec/assets/xref_error.err") }
23
- .from(false).to(true))
24
- end
25
- end
26
-
27
- it "Warns of illegal doctype" do
28
- FileUtils.rm_f "test.err"
29
- Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
30
- = Document title
31
- Author
32
- :docfile: test.adoc
33
- :nodoc:
34
- :no-isobib:
35
- :doctype: pizza
36
-
37
- text
38
- INPUT
39
- expect(File.read("test.err")).to include "pizza is not a recognised document type"
40
- end
41
-
42
- it "Warns of illegal function" do
43
- FileUtils.rm_f "test.err"
44
- Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
45
- = Document title
46
- Author
47
- :docfile: test.adoc
48
- :nodoc:
49
- :no-isobib:
50
- :function: pizza
51
-
52
- text
53
- INPUT
54
- expect(File.read("test.err")).to include "pizza is not a recognised document function"
55
- end
56
- end
data/spec/spec_helper.rb DELETED
@@ -1,305 +0,0 @@
1
- require "simplecov"
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- require "bundler/setup"
7
- require "asciidoctor"
8
- require "metanorma-iec"
9
- require "rspec/matchers"
10
- require "equivalent-xml"
11
- require "metanorma"
12
- require "metanorma/iec"
13
- require "iev"
14
- require "rexml/document"
15
-
16
- RSpec.configure do |config|
17
- # Enable flags like --only-failures and --next-failure
18
- config.example_status_persistence_file_path = ".rspec_status"
19
-
20
- # Disable RSpec exposing methods globally on `Module` and `main`
21
- config.disable_monkey_patching!
22
-
23
- config.expect_with :rspec do |c|
24
- c.syntax = :expect
25
- end
26
- end
27
-
28
- def metadata(xml)
29
- xml.sort.to_h.delete_if do |_k, v|
30
- v.nil? || (v.respond_to?(:empty?) && v.empty?)
31
- end
32
- end
33
-
34
- def strip_guid(xml)
35
- xml.gsub(%r{ id="_[^"]+"}, ' id="_"').gsub(%r{ target="_[^"]+"},
36
- ' target="_"')
37
- end
38
-
39
- def xmlpp(xml)
40
- c = HTMLEntities.new
41
- xml &&= xml.split(/(&\S+?;)/).map do |n|
42
- if /^&\S+?;$/.match?(n)
43
- c.encode(c.decode(n), :hexadecimal)
44
- else n
45
- end
46
- end.join
47
- s = ""
48
- f = REXML::Formatters::Pretty.new(2)
49
- f.compact = true
50
- f.write(REXML::Document.new(xml), s)
51
- s
52
- end
53
-
54
- OPTIONS = [backend: :iec, header_footer: true, agree_to_terms: true].freeze
55
-
56
- ASCIIDOC_BLANK_HDR = <<~"HDR".freeze
57
- = Document title
58
- Author
59
- :docfile: test.adoc
60
- :nodoc:
61
- :novalid:
62
- :no-isobib:
63
-
64
- HDR
65
-
66
- ISOBIB_BLANK_HDR = <<~"HDR".freeze
67
- = Document title
68
- Author
69
- :docfile: test.adoc
70
- :nodoc:
71
- :novalid:
72
- :no-isobib-cache:
73
-
74
- HDR
75
-
76
- FLUSH_CACHE_ISOBIB_BLANK_HDR = <<~"HDR".freeze
77
- = Document title
78
- Author
79
- :docfile: test.adoc
80
- :nodoc:
81
- :novalid:
82
- :flush-caches:
83
-
84
- HDR
85
-
86
- CACHED_ISOBIB_BLANK_HDR = <<~"HDR".freeze
87
- = Document title
88
- Author
89
- :docfile: test.adoc
90
- :nodoc:
91
- :novalid:
92
-
93
- HDR
94
-
95
- LOCAL_CACHED_ISOBIB_BLANK_HDR = <<~"HDR".freeze
96
- = Document title
97
- Author
98
- :docfile: test.adoc
99
- :nodoc:
100
- :novalid:
101
- :local-cache:
102
-
103
- HDR
104
-
105
- VALIDATING_BLANK_HDR = <<~"HDR".freeze
106
- = Document title
107
- Author
108
- :docfile: test.adoc
109
- :nodoc:
110
- :no-isobib:
111
-
112
- HDR
113
-
114
- TERMS_BOILERPLATE = <<~"BOILERPLATE".freeze
115
- <p id="_">ISO and IEC maintain terminological databases for use in
116
- standardization at the following addresses:</p>
117
- <ul id="_">
118
- <li> <p id="_">IEC Electropedia: available at
119
- <link target="http://www.electropedia.org"/>
120
- </p> </li>
121
- <li> <p id="_">ISO Online browsing platform: available at
122
- <link target="http://www.iso.org/obp"/></p> </li>
123
- </ul>
124
- BOILERPLATE
125
-
126
- def boilerplate(xmldoc)
127
- file = File.read(
128
- File.join(File.dirname(__FILE__), "..", "lib", "metanorma", "iec",
129
- "iec_intro_en.xml"), encoding: "utf-8"
130
- )
131
- conv = Metanorma::Iec::Converter.new(nil, backend: :iec,
132
- header_footer: true)
133
- conv.init(Asciidoctor::Document.new([]))
134
- ret = Nokogiri::XML(
135
- conv.boilerplate_isodoc(xmldoc).populate_template(file, nil)
136
- .gsub(/<p>/, "<p id='_'>")
137
- .gsub(/<ol>/, "<ol id='_'>"),
138
- )
139
- conv.smartquotes_cleanup(ret)
140
- HTMLEntities.new.decode(ret.to_xml)
141
- end
142
-
143
- BLANK_HDR = <<~"HDR".freeze
144
- <?xml version="1.0" encoding="UTF-8"?>
145
- <iec-standard xmlns="https://www.metanorma.org/ns/iec" type="semantic" version="#{Metanorma::Iec::VERSION}">
146
- <bibdata type="standard">
147
- <contributor>
148
- <role type="author"/>
149
- <organization>
150
- <name>International Electrotechnical Commission</name>
151
- <abbreviation>IEC</abbreviation>
152
- </organization>
153
- </contributor>
154
- <contributor>
155
- <role type="publisher"/>
156
- <organization>
157
- <name>International Electrotechnical Commission</name>
158
- <abbreviation>IEC</abbreviation>
159
- </organization>
160
- </contributor>
161
- <language>en</language>
162
- <script>Latn</script>
163
- <status>
164
- <stage abbreviation="PPUB">60</stage>
165
- <substage abbreviation="PPUB">60</substage>
166
- </status>
167
- <copyright>
168
- <from>#{Time.new.year}</from>
169
- <owner>
170
- <organization>
171
- <name>International Electrotechnical Commission</name>
172
- <abbreviation>IEC</abbreviation>
173
- </organization>
174
- </owner>
175
- </copyright>
176
- <ext>
177
- <doctype>standard</doctype>
178
- <editorialgroup>
179
- <agency>IEC</agency>
180
- </editorialgroup>
181
- <stagename>International standard</stagename>
182
- </ext>
183
- </bibdata>
184
- HDR
185
-
186
- def blank_hdr_gen
187
- <<~"HDR"
188
- #{BLANK_HDR}
189
- #{boilerplate(Nokogiri::XML("#{BLANK_HDR}</iec-standard>"))}
190
- HDR
191
- end
192
-
193
- IEC_TITLE = <<~TITLE.freeze
194
- <p class="zzSTDTitle1">INTERNATIONAL ELECTROTECHNICAL COMMISSION</p>
195
- <p class="zzSTDTitle1">____________</p>
196
- <p class="zzSTDTitle1">&#160;</p>
197
- <p class="zzSTDTitle1">
198
- <b/>
199
- </p>
200
- <p class="zzSTDTitle1">&#160;</p>
201
- TITLE
202
-
203
- IEC_TITLE1 = <<~TITLE.freeze
204
- <p class="zzSTDTitle1">
205
- <b/>
206
- </p>
207
- <p class="zzSTDTitle1">&#160;</p>
208
- TITLE
209
-
210
- HTML_HDR = <<~HDR.freeze
211
- <html xmlns:epub="http://www.idpf.org/2007/ops" lang="en">
212
- <head/>
213
- <body lang="en">
214
- <div class="title-section">
215
- <p>&#160;</p>
216
- </div>
217
- <br/>
218
- <div class="prefatory-section">
219
- <p>&#160;</p>
220
- </div>
221
- <br/>
222
- <div class="main-section">
223
- <br/>
224
- #{IEC_TITLE}
225
- HDR
226
-
227
- WORD_HDR = <<~HDR.freeze
228
- <html xmlns:epub="http://www.idpf.org/2007/ops">
229
- <head>
230
- <title>test</title>
231
- </head>
232
- <body lang="EN-US" link="blue" vlink="#954F72">
233
- <div class="WordSection1">
234
- <p>&#160;</p>
235
- </div>
236
- <p><br clear="all" class="section"/></p>
237
- <div class="WordSection2">
238
- <p>&#160;</p>
239
- </div>
240
- <p><br clear="all" class="section"/></p>
241
- <div class="WordSection3">
242
- HDR
243
-
244
- def stub_fetch_ref(**opts)
245
- xml = ""
246
-
247
- hit = double("hit")
248
- expect(hit).to receive(:[]).with("title") do
249
- Nokogiri::XML(xml).at("//docidentifier").content
250
- end.at_least(:once)
251
-
252
- hit_instance = double("hit_instance")
253
- expect(hit_instance).to receive(:hit).and_return(hit).at_least(:once)
254
- expect(hit_instance).to receive(:to_xml) do |builder, opt|
255
- expect(builder).to be_instance_of Nokogiri::XML::Builder
256
- expect(opt).to eq opts
257
- builder << xml
258
- end.at_least :once
259
-
260
- hit_page = double("hit_page")
261
- expect(hit_page).to receive(:first).and_return(hit_instance).at_least :once
262
-
263
- hit_pages = double("hit_pages")
264
- expect(hit_pages).to receive(:first).and_return(hit_page).at_least :once
265
-
266
- expect(Isobib::IsoBibliography).to receive(:search)
267
- .and_wrap_original do |search, *args|
268
- code = args[0]
269
- expect(code).to be_instance_of String
270
- xml = get_xml(search, code, opts)
271
- hit_pages
272
- end.at_least :once
273
- end
274
-
275
- def mock_pdf
276
- allow(::Mn2pdf).to receive(:convert) do |url, output, _c, _d|
277
- FileUtils.cp(url.gsub(/"/, ""), output.gsub(/"/, ""))
278
- end
279
- end
280
-
281
- private
282
-
283
- def get_xml(search, code, opts)
284
- c = code.gsub(%r{[/\s:-]}, "_").sub(%r{_+$}, "").downcase
285
- o = opts.keys.join "_"
286
- file = "spec/examples/#{[c, o].join '_'}.xml"
287
- if File.exist? file
288
- File.read file
289
- else
290
- result = search.call(code)
291
- hit = result&.first&.first
292
- xml = hit.to_xml nil, opts
293
- File.write file, xml
294
- xml
295
- end
296
- end
297
-
298
- def mock_open_uri(code)
299
- # expect(OpenURI).to receive(:open_uri).and_wrap_original do |m, *args|
300
- expect(Iev).to receive(:get).with(code, "en") do |m, *args|
301
- file = "spec/examples/#{code.tr('-', '_')}.html"
302
- File.write file, m.call(*args).read unless File.exist? file
303
- File.read file
304
- end.at_least :once
305
- end