debian-mirror-gitlab/spec/serializers/codequality_degradation_entity_spec.rb

57 lines
2.4 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe CodequalityDegradationEntity do
let(:entity) { described_class.new(codequality_degradation) }
describe '#as_json' do
subject { entity.as_json }
context 'when codequality contains an error' do
context 'when line is included in location' do
2021-03-11 19:13:27 +05:30
let(:codequality_degradation) { build(:codequality_degradation_2) }
2021-02-22 17:27:13 +05:30
it 'contains correct codequality degradation details', :aggregate_failures do
expect(subject[:description]).to eq("Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.")
expect(subject[:severity]).to eq("major")
2021-03-11 19:13:27 +05:30
expect(subject[:file_path]).to eq("file_a.rb")
2021-02-22 17:27:13 +05:30
expect(subject[:line]).to eq(10)
2023-01-13 00:05:48 +05:30
expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_a.rb#L10")
2023-04-23 21:23:45 +05:30
expect(subject[:engine_name]).to eq('structure')
2021-02-22 17:27:13 +05:30
end
end
context 'when line is included in positions' do
2021-03-11 19:13:27 +05:30
let(:codequality_degradation) { build(:codequality_degradation_3) }
2021-02-22 17:27:13 +05:30
it 'contains correct codequality degradation details', :aggregate_failures do
expect(subject[:description]).to eq("Avoid parameter lists longer than 5 parameters. [12/5]")
expect(subject[:severity]).to eq("minor")
2021-03-11 19:13:27 +05:30
expect(subject[:file_path]).to eq("file_b.rb")
expect(subject[:line]).to eq(10)
2023-01-13 00:05:48 +05:30
expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_b.rb#L10")
2023-04-23 21:23:45 +05:30
expect(subject[:engine_name]).to eq('rubocop')
2021-02-22 17:27:13 +05:30
end
end
2022-04-04 11:22:00 +05:30
context 'when severity is capitalized' do
let(:codequality_degradation) { build(:codequality_degradation_3) }
before do
codequality_degradation[:severity] = 'MINOR'
end
it 'lowercases severity', :aggregate_failures do
expect(subject[:description]).to eq("Avoid parameter lists longer than 5 parameters. [12/5]")
expect(subject[:severity]).to eq("minor")
expect(subject[:file_path]).to eq("file_b.rb")
expect(subject[:line]).to eq(10)
2023-01-13 00:05:48 +05:30
expect(subject[:web_url]).to eq("http://localhost/root/test-project/-/blob/f572d396fae9206628714fb2ce00f72e94f2258f/file_b.rb#L10")
2023-04-23 21:23:45 +05:30
expect(subject[:engine_name]).to eq('rubocop')
2022-04-04 11:22:00 +05:30
end
end
2021-02-22 17:27:13 +05:30
end
end
end