blob: e7aad806473f6475b6c82ab94dd7445814092588 (
plain) (
blame)
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
|
# frozen_string_literal: true
ASCIIDOCTOR_FEATURES_DIR = File.absolute_path __dir__
ASCIIDOCTOR_LIB_DIR = ENV['ASCIIDOCTOR_LIB_DIR'] || File.join(ASCIIDOCTOR_FEATURES_DIR, '../lib')
require 'simplecov' if ENV['COVERAGE'] == 'true'
require File.join ASCIIDOCTOR_LIB_DIR, 'asciidoctor'
Dir.chdir Asciidoctor::ROOT_DIR
require 'rspec/expectations'
require 'tilt'
require 'slim'
Given /the AsciiDoc source/ do |source|
@source = source
end
When /it is converted to html/ do
@output = Asciidoctor.convert @source
end
When /it is converted to docbook/ do
@output = Asciidoctor.convert @source, backend: :docbook
end
Then /the result should (match|contain) the (HTML|XML) source/ do |matcher, format, expected|
match_expectation = matcher == 'match' ? (eq expected) : (include expected)
(expect @output).to match_expectation
end
Then /the result should (match|contain) the (HTML|XML) structure/ do |matcher, format, expected|
result = @output
if format == 'HTML'
options = { format: :html, disable_escape: true, sort_attrs: false }
else # format == 'XML'
options = { format: :xhtml, disable_escape: true, sort_attrs: false }
result = result.gsub '"/>', '" />' if result.include? '"/>'
end
result = Slim::Template.new(options) { result.each_line.map {|l| (l.start_with? '<') ? l : %(|#{l}) }.join }.render
expected = Slim::Template.new(options) { expected }.render
match_expectation = matcher == 'match' ? (eq expected) : (include expected)
(expect result).to match_expectation
end
|