Commit 52f8286a authored by Rubén Dávila's avatar Rubén Dávila

Update specs. #3945

parent 6282202e
......@@ -6,24 +6,24 @@ describe Gitlab::Diff::Highlight, lib: true do
let(:project) { create(:project) }
let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) }
let(:diff_file) { Gitlab::Diff::File.new(diff, [commit.parent.id, commit.id], project.repository) }
describe '.process_diff_lines' do
context 'when processing Gitlab::Diff::Line objects' do
let(:diff_lines) { Gitlab::Diff::Highlight.process_diff_lines(diff_file.new_path, diff_file.diff_lines) }
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{<span id="LC3" 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}
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}
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('<span class="idiff">RuntimeError, </span>')))
it 'should not generate the inline diff markup' do
expect(diff_lines[5].text).not_to match(Regexp.new(Regexp.escape('<span class="idiff">')))
end
it 'should not modify "match" lines' do
......@@ -31,19 +31,18 @@ describe Gitlab::Diff::Highlight, lib: true do
expect(diff_lines[22].text).to eq('@@ -19,6 +25,7 @@ module Popen')
end
end
end
context 'when processing raw lines' do
let(:lines) { ["puts 'Hello'\n", "# A comment"] }
let(:highlighted_lines) { Gitlab::Diff::Highlight.process_diff_lines('demo.rb', lines) }
it 'should highlight the code' do
line_1 = %Q{<span id="LC1" class="line"><span class="nb">puts</span> <span class="s1">&#39;Hello&#39;</span></span>\n}
line_2 = %Q{<span id="LC2" class="line"><span class="c1"># A comment</span></span>}
expect(highlighted_lines[0]).to eq(line_1)
expect(highlighted_lines[1]).to eq(line_2)
end
describe '.process_file' do
let(:lines) do
Gitlab::Diff::Highlight.process_file(project.repository, commit.id, 'files/ruby/popen.rb')
end
it 'should properly highlight all the lines' do
expect(lines[4]).to eq(%Q{<span id="LC5" class="line"> <span class="kp">extend</span> <span class="nb">self</span></span>\n})
expect(lines[21]).to eq(%Q{<span id="LC22" class="line"> <span class="k">unless</span> <span class="no">File</span><span class="p">.</span><span class="nf">directory?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>\n})
expect(lines[26]).to eq(%Q{<span id="LC27" class="line"> <span class="vi">@cmd_status</span> <span class="o">=</span> <span class="mi">0</span></span>\n})
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment