diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2018-01-30 18:41:17 +0100 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2018-01-30 19:38:24 +0100 |
commit | 98fef6b4e84014c5d0f13653b0fe838918c29323 (patch) | |
tree | dd912d82344fc164ddcc8b8b09eda929cffd49de /spec | |
parent | 9335f9fc0950004f477e86d6332b6e26dbf05025 (diff) |
Add integration tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/b/c/doc-c.adoc | 3 | ||||
-rw-r--r-- | spec/fixtures/b/doc-b.adoc | 3 | ||||
-rw-r--r-- | spec/fixtures/doc-a.adoc | 10 | ||||
-rw-r--r-- | spec/integration_spec.rb | 109 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
5 files changed, 127 insertions, 0 deletions
diff --git a/spec/fixtures/b/c/doc-c.adoc b/spec/fixtures/b/c/doc-c.adoc new file mode 100644 index 0000000..7da2676 --- /dev/null +++ b/spec/fixtures/b/c/doc-c.adoc @@ -0,0 +1,3 @@ += Document C + +xref:../doc-b#[] diff --git a/spec/fixtures/b/doc-b.adoc b/spec/fixtures/b/doc-b.adoc new file mode 100644 index 0000000..9ed3a43 --- /dev/null +++ b/spec/fixtures/b/doc-b.adoc @@ -0,0 +1,3 @@ += Document B + +xref:c/doc-c#[] diff --git a/spec/fixtures/doc-a.adoc b/spec/fixtures/doc-a.adoc new file mode 100644 index 0000000..1803892 --- /dev/null +++ b/spec/fixtures/doc-a.adoc @@ -0,0 +1,10 @@ += Document A + +Some text. + +== First Section + +== Second Section [[sec2]] + +[reftext="3rd Section"] +== Third Section 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 80e5bc6..a03e89e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,9 @@ require 'rspec' +require 'rspec-html-matchers' RSpec.configure do |config| config.color = true + config.include RSpecHtmlMatchers end unless RUBY_ENGINE == 'jruby' |