diff options
Diffstat (limited to 'spec/integration_spec.rb')
-rw-r--r-- | spec/integration_spec.rb | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb new file mode 100644 index 0000000..883bbb2 --- /dev/null +++ b/spec/integration_spec.rb @@ -0,0 +1,109 @@ +require_relative 'spec_helper' + +require 'asciidoctor/interdoc_reftext/processor' +require 'asciidoctor' +require 'corefines' + +using Corefines::String::unindent +using Corefines::Hash::except + +FIXTURES_DIR = File.expand_path('fixtures', __dir__) + + +describe 'Intengration Tests' do + + subject(:output) { Asciidoctor.convert(input, options) } + + let(:input) { '' } # this is modified in #given + let(:processor) { Asciidoctor::InterdocReftext::Processor.new } + + let(:options) { + processor_ = processor + { + safe: :safe, + header_footer: false, + base_dir: FIXTURES_DIR, + extensions: proc { tree_processor processor_ }, + } + } + + context 'document with valid inter-document xref without reftext' do + + context 'without fragment' do + it 'renders title of the referenced document as reftext' do + given 'xref:doc-a#[]' + should have_anchor href: 'doc-a.html', text: 'Document A' + end + end + + context 'with fragment' do + it 'renders title of the referenced section with implicit id as reftext' do + given 'xref:doc-a#_first_section[]' + should have_anchor href: 'doc-a.html#_first_section', text: 'First Section' + end + + it 'renders title of the referenced section with explicit id as reftext' do + given 'xref:doc-a#sec2[]' + should have_anchor href: 'doc-a.html#sec2', text: 'Second Section' + end + + it 'renders reftext of the referenced section with explicit reftext' do + given 'xref:doc-a#_third_section[]' + should have_anchor href: 'doc-a.html#_third_section', text: '3rd Section' + end + end + + context 'with relative path' do + subject(:output) do + opts = options.except(:base_dir) + Asciidoctor.load_file("#{FIXTURES_DIR}/b/doc-b.adoc", opts).convert + end + + it 'resolves path relative to the current document' do + should have_anchor href: 'c/doc-c.html', text: 'Document C' + end + end + + context 'when extension is not active' do + specify 'renders path of the referenced document as reftext' do + given 'xref:doc-a#[]', extensions: [] + should have_anchor href: 'doc-a.html', text: 'doc-a.html' + end + end + end + + context 'document with invalid inter-document xref without reftext' do + + context 'without fragment' do + it 'renders path of the non-existent document as reftext' do + given 'xref:missing#[]' + should have_anchor href: 'missing.html', text: 'missing.html' + end + end + + context 'with non-existent fragment' do + it 'renders path of the referenced document as reftext' do + given 'xref:doc-a#missing[]' + should have_anchor href: 'doc-a.html#missing', text: 'doc-a.html' + end + end + end + + context 'document with valid inter-document xref with reftext' do + it 'renders provided reftext' do + given 'xref:doc-a#[My Title]' + should have_anchor href: 'doc-a.html', text: 'My Title' + end + end + + #---------- Helpers ---------- + + def given(str, opts = {}) + input.replace(str) + options.merge!(opts) + end + + def have_anchor(href: nil, text: nil) + have_tag('a', with: { href: href }, text: text) + end +end |