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

module Gitlab
Douwe Maan's avatar
Douwe Maan committed
5
  describe Asciidoc, lib: true do
6 7 8 9 10 11
    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
12 13 14 15 16
        expected_asciidoc_opts = {
            safe: :secure,
            backend: :html5,
            attributes: described_class::DEFAULT_ADOC_ATTRS
        }
17 18 19 20 21 22 23 24

        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
25
        let(:asciidoc_opts) { { safe: :safe, attributes: ['foo'] } }
26 27

        it "should merge the options with default ones" do
28 29 30 31 32
          expected_asciidoc_opts = {
              safe: :safe,
              backend: :html5,
              attributes: described_class::DEFAULT_ADOC_ATTRS + ['foo']
          }
33 34 35 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

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