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

73 lines
2.2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-18 11:00:15 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe TestCaseEntity do
2018-11-18 11:00:15 +05:30
include TestReportsHelper
2020-11-24 15:15:51 +05:30
let_it_be(:job) { create(:ci_build) }
2018-11-18 11:00:15 +05:30
let(:entity) { described_class.new(test_case) }
describe '#as_json' do
subject { entity.as_json }
context 'when test case is success' do
let(:test_case) { create_test_case_rspec_success }
it 'contains correct test case details' do
expect(subject[:status]).to eq('success')
expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary')
2019-09-04 21:01:54 +05:30
expect(subject[:classname]).to eq('spec.test_spec')
2021-01-03 14:25:43 +05:30
expect(subject[:file]).to eq('./spec/test_spec.rb')
2018-11-18 11:00:15 +05:30
expect(subject[:execution_time]).to eq(1.11)
end
end
context 'when test case is failed' do
let(:test_case) { create_test_case_rspec_failed }
2021-01-29 00:20:46 +05:30
before do
test_case.set_recent_failures(3, 'master')
end
2018-11-18 11:00:15 +05:30
it 'contains correct test case details' do
expect(subject[:status]).to eq('failed')
2019-09-30 21:07:59 +05:30
expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary')
2019-09-04 21:01:54 +05:30
expect(subject[:classname]).to eq('spec.test_spec')
2021-01-03 14:25:43 +05:30
expect(subject[:file]).to eq('./spec/test_spec.rb')
2018-11-18 11:00:15 +05:30
expect(subject[:execution_time]).to eq(2.22)
2021-01-29 00:20:46 +05:30
expect(subject[:recent_failures]).to eq({ count: 3, base_branch: 'master' })
2018-11-18 11:00:15 +05:30
end
end
2020-04-22 19:07:51 +05:30
2022-04-04 11:22:00 +05:30
context 'when no test name is entered' do
let(:test_case) { build(:report_test_case, name: "") }
it 'contains correct test case details' do
expect(subject[:status]).to eq('success')
expect(subject[:name]).to eq('(No name)')
expect(subject[:classname]).to eq('trace')
expect(subject[:file]).to eq('spec/trace_spec.rb')
expect(subject[:execution_time]).to eq(1.23)
end
end
2021-06-08 01:23:25 +05:30
context 'when attachment is present' do
let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) }
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
it 'returns the attachment_url' do
expect(subject).to include(:attachment_url)
2020-04-22 19:07:51 +05:30
end
end
2021-06-08 01:23:25 +05:30
context 'when attachment is not present' do
let(:test_case) { build(:report_test_case, job: job) }
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
it 'returns a nil attachment_url' do
expect(subject[:attachment_url]).to be_nil
2020-04-22 19:07:51 +05:30
end
end
2018-11-18 11:00:15 +05:30
end
end