asciidoc_spec.rb 1.7 KB
Newer Older
1 2 3 4
require 'spec_helper'
require 'nokogiri'

module Gitlab
D
Douwe Maan 已提交
5
  describe Asciidoc, lib: true do
6 7 8 9 10 11 12 13

    let(:input) { '<b>ascii</b>' }
    let(:context) { {} }
    let(:html) { 'H<sub>2</sub>O' }

    context "without project" do

      it "should convert the input using Asciidoctor and default options" do
S
Stan Hu 已提交
14 15 16 17 18
        expected_asciidoc_opts = {
            safe: :secure,
            backend: :html5,
            attributes: described_class::DEFAULT_ADOC_ATTRS
        }
19 20 21 22 23 24 25 26 27

        expect(Asciidoctor).to receive(:convert)
          .with(input, expected_asciidoc_opts).and_return(html)

        expect( render(input, context) ).to eql html
      end

      context "with asciidoc_opts" do

28
        let(:asciidoc_opts) { { safe: :safe, attributes: ['foo'] } }
29 30

        it "should merge the options with default ones" do
S
Stan Hu 已提交
31 32 33 34 35
          expected_asciidoc_opts = {
              safe: :safe,
              backend: :html5,
              attributes: described_class::DEFAULT_ADOC_ATTRS + ['foo']
          }
36 37 38 39 40 41 42 43 44 45 46

          expect(Asciidoctor).to receive(:convert)
            .with(input, expected_asciidoc_opts).and_return(html)

          render(input, context, asciidoc_opts)
        end
      end
    end

    context "with project in context" do

47
      let(:context) { { project: create(:project) } }
48 49 50 51 52

      it "should filter converted input via HTML pipeline and return result" do
        filtered_html = '<b>ASCII</b>'

        allow(Asciidoctor).to receive(:convert).and_return(html)
53
        expect(Banzai).to receive(:render)
54 55
          .with(html, context.merge(pipeline: :asciidoc))
          .and_return(filtered_html)
56 57 58 59 60 61 62 63 64 65

        expect( render('foo', context) ).to eql filtered_html
      end
    end

    def render(*args)
      described_class.render(*args)
    end
  end
end