Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-09-10 18:23:10 +0300
committerStan Hu <stanhu@gmail.com>2015-09-10 19:16:27 +0300
commit9d3344adbbfc84ef8abc96366bdfa695293cd6c0 (patch)
treeefe45a503b814013a06d8e77b112b74c6ec4d6a9 /spec
parent1c3c3ba512a85cdf0c09ac4750bcd7955009d6d4 (diff)
Gracefully handle errors in syntax highlighting by leaving the block unformatted
Closes #2433
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb b/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb
new file mode 100644
index 00000000000..ecef31853f4
--- /dev/null
+++ b/spec/lib/gitlab/markdown/syntax_highlight_filter_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+module Gitlab::Markdown
+ describe SyntaxHighlightFilter do
+ include FilterSpecHelper
+
+ let(:project) { create(:empty_project) }
+ let(:reference) { snippet.to_reference }
+
+ it 'highlights valid code blocks' do
+ result = filter('<pre><code>def fun end</code>')
+ expect(result.to_html).to eq("<pre class=\"code highlight js-syntax-highlight plaintext\"><code>def fun end</code></pre>\n")
+ end
+
+ it 'passes through invalid code blocks' do
+ allow_any_instance_of(SyntaxHighlightFilter).to receive(:block_code).and_raise(StandardError)
+
+ result = filter('<pre><code>This is a test</code></pre>')
+ expect(result.to_html).to eq('<pre>This is a test</pre>')
+ end
+ end
+end