debian-mirror-gitlab/spec/lib/banzai/filter/markdown_filter_spec.rb

64 lines
1.8 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Banzai::Filter::MarkdownFilter do
2017-08-17 22:00:37 +05:30
include FilterSpecHelper
2018-11-08 19:23:39 +05:30
describe 'markdown engine from context' do
it 'defaults to CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
filter('test')
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it 'uses Redcarpet' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::Redcarpet).to receive(:render).and_return('test')
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
filter('test', { markdown_engine: :redcarpet })
end
it 'uses CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
filter('test', { markdown_engine: :common_mark })
end
end
describe 'code block' do
context 'using CommonMark' do
before do
stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark)
end
it 'adds language to lang attribute when specified' do
result = filter("```html\nsome code\n```")
expect(result).to start_with("<pre><code lang=\"html\">")
end
it 'does not add language to lang attribute when not specified' do
result = filter("```\nsome code\n```")
expect(result).to start_with("<pre><code>")
end
end
context 'using Redcarpet' do
before do
stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :redcarpet)
end
it 'adds language to lang attribute when specified' do
result = filter("```html\nsome code\n```")
expect(result).to start_with("\n<pre><code lang=\"html\">")
end
it 'does not add language to lang attribute when not specified' do
result = filter("```\nsome code\n```")
expect(result).to start_with("\n<pre><code>")
end
2017-08-17 22:00:37 +05:30
end
end
end