highlight_spec.rb 1.8 KB
Newer Older
1 2 3 4 5 6 7 8
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 }
9
  let(:diff_file) { Gitlab::Diff::File.new(diff, [commit.parent, commit]) }
10

11 12
  describe '#highlight' do
    let(:diff_lines) { Gitlab::Diff::Highlight.new(diff_file).highlight }
13

14 15 16
    it 'should return Gitlab::Diff::Line elements' do
      expect(diff_lines.first).to be_an_instance_of(Gitlab::Diff::Line)
    end
R
Rubén Dávila 已提交
17

18 19 20 21
    it 'should not modify "match" lines' do
      expect(diff_lines[0].text).to eq('@@ -6,12 +6,18 @@ module Popen')
      expect(diff_lines[22].text).to eq('@@ -19,6 +25,7 @@ module Popen')
    end
R
Rubén Dávila 已提交
22

23 24
    it 'should highlight unchanged lines' do
      code = %Q{ <span id="LC7" class="line">  <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>\n}
R
Rubén Dávila 已提交
25

26 27
      expect(diff_lines[2].text).to eq(code)
    end
R
Rubén Dávila 已提交
28

29 30
    it 'should highlight removed lines' do
      code = %Q{-<span id="LC9" class="line">      <span class="k">raise</span> <span class="s2">&quot;System commands must be given as an array of strings&quot;</span></span>\n}
R
Rubén Dávila 已提交
31

32
      expect(diff_lines[4].text).to eq(code)
33
    end
34

35
    it 'should highlight added lines' do
D
Douwe Maan 已提交
36
      code = %Q{+<span id="LC9" class="line">      <span class="k">raise</span> <span class="no"><span class='idiff'>RuntimeError</span></span><span class="p"><span class='idiff'>,</span></span><span class='idiff'> </span><span class="s2">&quot;System commands must be given as an array of strings&quot;</span></span>\n}
37

38
      expect(diff_lines[5].text).to eq(code)
R
Rubén Dávila 已提交
39
    end
40 41
  end
end