require 'spec_helper' describe GrapeSwagger::Markdown::RedcarpetAdapter, unless: RUBY_PLATFORM.eql?('java') do context 'initialization' do context 'initialization' do it 'uses fenced_code_blocks, auto_links and rouge as default.' do expect_any_instance_of(GrapeSwagger::Markdown::RedcarpetAdapter).to receive(:new_redcarpet_renderer).with(:rouge).and_call_original adapter = GrapeSwagger::Markdown::RedcarpetAdapter.new expect(adapter.extension_options).to eq(fenced_code_blocks: true, autolink: true) expect(adapter.render_options).to eq({}) end it 'initializes with no highlighter.' do expect_any_instance_of(GrapeSwagger::Markdown::RedcarpetAdapter).to receive(:new_redcarpet_renderer).with(:none).and_call_original adapter = GrapeSwagger::Markdown::RedcarpetAdapter.new render_options: { highlighter: :none } expect(adapter.extension_options).to eq(fenced_code_blocks: true, autolink: true) expect(adapter.render_options).to eq({}) end it 'overrides default values' do extensions = { fenced_code_blocks: true, autolink: true } render_options = { highlighter: :none, no_links: true } adapter = GrapeSwagger::Markdown::RedcarpetAdapter.new extensions: extensions, render_options: render_options expect(adapter.extension_options).to eq(extensions) expect(adapter.render_options).to eq(no_links: true) end it 'raises an GrapeSwagger::Errors::MarkdownDependencyMissingError if module can not be required.' do expect_any_instance_of(Kernel).to receive(:require).with('redcarpet').and_raise(LoadError) expect { GrapeSwagger::Markdown::RedcarpetAdapter.new }.to raise_error(GrapeSwagger::Errors::MarkdownDependencyMissingError, 'Missing required dependency: redcarpet') end end context 'markdown' do it 'marks down with the configured options' do text = '# hello world #' extensions = { fenced_code_blocks: true, autolink: true } render_options = { highlighter: :none, no_links: true, highlighter: :none } expect_any_instance_of(Redcarpet::Markdown).to receive(:render).with(text).and_call_original output = GrapeSwagger::Markdown::RedcarpetAdapter.new(extensions: extensions, render_options: render_options).markdown(text) expect(output).to include('