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

78 lines
2.2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe TestSuiteEntity do
let(:pipeline) { create(:ci_pipeline, :with_test_reports) }
2020-05-24 23:13:21 +05:30
let(:test_suite) { pipeline.test_reports.test_suites.each_value.first }
2020-07-28 23:09:34 +05:30
let(:user) { create(:user) }
let(:request) { double('request', current_user: user) }
2019-12-21 20:55:43 +05:30
2020-07-28 23:09:34 +05:30
subject { described_class.new(test_suite, request: request).as_json }
context 'when details option is not present' do
it 'does not expose suite error and test cases', :aggregate_failures do
expect(subject).not_to include(:test_cases)
expect(subject).not_to include(:suite_error)
end
end
context 'when details option is present' do
subject { described_class.new(test_suite, request: request, details: true).as_json }
2019-12-21 20:55:43 +05:30
it 'contains the suite name' do
2020-07-28 23:09:34 +05:30
expect(subject[:name]).to be_present
2019-12-21 20:55:43 +05:30
end
it 'contains the total time' do
2020-07-28 23:09:34 +05:30
expect(subject[:total_time]).to be_present
2019-12-21 20:55:43 +05:30
end
it 'contains the counts' do
2020-07-28 23:09:34 +05:30
expect(subject[:total_count]).to eq(4)
expect(subject[:success_count]).to eq(2)
expect(subject[:failed_count]).to eq(2)
expect(subject[:skipped_count]).to eq(0)
expect(subject[:error_count]).to eq(0)
2019-12-21 20:55:43 +05:30
end
it 'contains the test cases' do
2020-07-28 23:09:34 +05:30
expect(subject[:test_cases].count).to eq(4)
2019-12-21 20:55:43 +05:30
end
2020-05-24 23:13:21 +05:30
it 'contains an empty error message' do
2020-07-28 23:09:34 +05:30
expect(subject[:suite_error]).to be_nil
2020-05-24 23:13:21 +05:30
end
context 'with a suite error' do
before do
test_suite.set_suite_error('a really bad error')
end
it 'contains the suite name' do
2020-07-28 23:09:34 +05:30
expect(subject[:name]).to be_present
2020-05-24 23:13:21 +05:30
end
it 'contains the total time' do
2020-07-28 23:09:34 +05:30
expect(subject[:total_time]).to be_present
2020-05-24 23:13:21 +05:30
end
it 'returns all the counts as 0' do
2020-07-28 23:09:34 +05:30
expect(subject[:total_count]).to eq(0)
expect(subject[:success_count]).to eq(0)
expect(subject[:failed_count]).to eq(0)
expect(subject[:skipped_count]).to eq(0)
expect(subject[:error_count]).to eq(0)
2020-05-24 23:13:21 +05:30
end
it 'returns no test cases' do
2020-07-28 23:09:34 +05:30
expect(subject[:test_cases]).to be_empty
2020-05-24 23:13:21 +05:30
end
it 'returns a suite error' do
2020-07-28 23:09:34 +05:30
expect(subject[:suite_error]).to eq('a really bad error')
2020-05-24 23:13:21 +05:30
end
end
2019-12-21 20:55:43 +05:30
end
end