59 lines
1.4 KiB
Ruby
59 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.shared_examples "position formatter" do
|
|
let(:formatter) { described_class.new(attrs) }
|
|
|
|
describe '#key' do
|
|
let(:key) { [123, 456, 789, Digest::SHA1.hexdigest(formatter.old_path), Digest::SHA1.hexdigest(formatter.new_path), 1, 2] }
|
|
|
|
subject { formatter.key }
|
|
|
|
it { is_expected.to eq(key) }
|
|
end
|
|
|
|
describe '#complete?' do
|
|
subject { formatter.complete? }
|
|
|
|
context 'when there are missing key attributes' do
|
|
it { is_expected.to be_truthy }
|
|
end
|
|
|
|
context 'when old_line and new_line are nil' do
|
|
let(:attrs) { base_attrs }
|
|
|
|
it { is_expected.to be_falsy }
|
|
end
|
|
end
|
|
|
|
describe '#to_h' do
|
|
let(:formatter_hash) do
|
|
attrs.merge(position_type: base_attrs[:position_type] || 'text' )
|
|
end
|
|
|
|
subject { formatter.to_h }
|
|
|
|
context 'when file_identifier_hash is disabled' do
|
|
before do
|
|
stub_feature_flags(file_identifier_hash: false)
|
|
end
|
|
|
|
it { is_expected.to eq(formatter_hash.except(:file_identifier_hash)) }
|
|
end
|
|
|
|
context 'when file_identifier_hash is enabled' do
|
|
before do
|
|
stub_feature_flags(file_identifier_hash: true)
|
|
end
|
|
|
|
it { is_expected.to eq(formatter_hash) }
|
|
end
|
|
end
|
|
|
|
describe '#==' do
|
|
subject { formatter }
|
|
|
|
let(:other_formatter) { described_class.new(attrs) }
|
|
|
|
it { is_expected.to eq(other_formatter) }
|
|
end
|
|
end
|