debian-mirror-gitlab/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Diff::Formatters::TextFormatter do
2018-03-17 18:26:18 +05:30
let!(:base) do
{
base_sha: 123,
start_sha: 456,
head_sha: 789,
old_path: 'old_path.txt',
2020-04-22 19:07:51 +05:30
new_path: 'new_path.txt',
2020-06-23 00:09:42 +05:30
file_identifier_hash: '777',
2020-04-22 19:07:51 +05:30
line_range: nil
2018-03-17 18:26:18 +05:30
}
end
let!(:complete) do
base.merge(old_line: 1, new_line: 2)
end
it_behaves_like "position formatter" do
let(:base_attrs) { base }
let(:attrs) { complete }
end
# Specific text formatter examples
let!(:formatter) { described_class.new(attrs) }
2020-05-24 23:13:21 +05:30
let(:attrs) { base }
2018-03-17 18:26:18 +05:30
describe '#line_age' do
subject { formatter.line_age }
context ' when there is only new_line' do
let(:attrs) { base.merge(new_line: 1) }
it { is_expected.to eq('new') }
end
context ' when there is only old_line' do
let(:attrs) { base.merge(old_line: 1) }
it { is_expected.to eq('old') }
end
end
2020-05-24 23:13:21 +05:30
describe "#==" do
it "is false when the line_range changes" do
formatter_1 = described_class.new(base.merge(line_range: { start_line_code: "foo", end_line_code: "bar" }))
formatter_2 = described_class.new(base.merge(line_range: { start_line_code: "foo", end_line_code: "baz" }))
expect(formatter_1).not_to eq(formatter_2)
end
it "is true when the line_range doesn't change" do
attrs = base.merge({ line_range: { start_line_code: "foo", end_line_code: "baz" } })
formatter_1 = described_class.new(attrs)
formatter_2 = described_class.new(attrs)
expect(formatter_1).to eq(formatter_2)
end
end
2018-03-17 18:26:18 +05:30
end