From d83275620a0eeaf17a2958e59e2b4d6f217c6464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= Date: Wed, 30 Dec 2015 20:18:40 -0500 Subject: [PATCH] Add specs for Gitlab::Diff::Highlight. #3945 --- spec/lib/gitlab/diff/highlight_spec.rb | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/lib/gitlab/diff/highlight_spec.rb diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb new file mode 100644 index 00000000000..2a827a08dba --- /dev/null +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Gitlab::Diff::Highlight, lib: true do + include RepoHelpers + + let(:project) { create(:project) } + let(:commit) { project.commit(sample_commit.id) } + let(:diff) { commit.diffs.first } + let(:diff_file) { Gitlab::Diff::File.new(diff) } + + describe '.process_diff_lines' do + let(:diff_lines) { Gitlab::Diff::Highlight.process_diff_lines(diff_file) } + + it 'should return Gitlab::Diff::Line elements' do + expect(diff_lines.first).to be_an_instance_of(Gitlab::Diff::Line) + end + + it 'should highlight the code' do + code = %Q{ def popen(cmd, path=nil)\n} + + expect(diff_lines[2].text).to eq(code) + end + + it 'should keep the inline diff markup' do + expect(diff_lines[5].text).to match(Regexp.new(Regexp.escape('RuntimeError, '))) + end + end +end