diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 03:07:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 03:07:49 +0300 |
commit | 5d32a7a175fd1a7a6c97019a022c11434ea637dc (patch) | |
tree | 8741a075a83a139de103915278b87e66da6efb03 /spec | |
parent | d74fcc9b69746c4d9582299c370a95aafe2ac3ac (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/test_case.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/reports/test_case_spec.rb | 62 |
2 files changed, 20 insertions, 49 deletions
diff --git a/spec/factories/ci/test_case.rb b/spec/factories/ci/test_case.rb index dc0e7c762ab..bb1508c0d75 100644 --- a/spec/factories/ci/test_case.rb +++ b/spec/factories/ci/test_case.rb @@ -6,17 +6,18 @@ FactoryBot.define do classname { "trace" } file { "spec/trace_spec.rb" } execution_time { 1.23 } - status { "success" } + status { Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS } system_output { nil } attachment { nil } association :job, factory: :ci_build trait :failed do - status { "failed" } + status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } + system_output { "Failure/Error: is_expected.to eq(300) expected: 300 got: -100" } end trait :with_attachment do - status { "failed" } + status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } attachment { "some/path.png" } end diff --git a/spec/lib/gitlab/ci/reports/test_case_spec.rb b/spec/lib/gitlab/ci/reports/test_case_spec.rb index 69fe05d573e..c0652288cca 100644 --- a/spec/lib/gitlab/ci/reports/test_case_spec.rb +++ b/spec/lib/gitlab/ci/reports/test_case_spec.rb @@ -4,21 +4,12 @@ require 'spec_helper' describe Gitlab::Ci::Reports::TestCase do describe '#initialize' do - let(:test_case) { described_class.new(**params)} + let(:test_case) { described_class.new(params)} context 'when both classname and name are given' do context 'when test case is passed' do - let(:params) do - { - name: 'test-1', - classname: 'trace', - file: 'spec/trace_spec.rb', - execution_time: 1.23, - status: described_class::STATUS_SUCCESS, - system_output: nil, - job: build(:ci_build) - } - end + let(:job) { build(:ci_build) } + let(:params) { attributes_for(:test_case).merge!(job: job) } it 'initializes an instance' do expect { test_case }.not_to raise_error @@ -34,16 +25,8 @@ describe Gitlab::Ci::Reports::TestCase do end context 'when test case is failed' do - let(:params) do - { - name: 'test-1', - classname: 'trace', - file: 'spec/trace_spec.rb', - execution_time: 1.23, - status: described_class::STATUS_FAILED, - system_output: "Failure/Error: is_expected.to eq(300) expected: 300 got: -100" - } - end + let(:job) { build(:ci_build) } + let(:params) { attributes_for(:test_case, :failed).merge!(job: job) } it 'initializes an instance' do expect { test_case }.not_to raise_error @@ -59,36 +42,23 @@ describe Gitlab::Ci::Reports::TestCase do end end - context 'when classname is missing' do - let(:params) do - { - name: 'test-1', - file: 'spec/trace_spec.rb', - execution_time: 1.23, - status: described_class::STATUS_SUCCESS, - system_output: nil - } - end + shared_examples 'param is missing' do |param| + let(:job) { build(:ci_build) } + let(:params) { attributes_for(:test_case).merge!(job: job) } it 'raises an error' do - expect { test_case }.to raise_error(ArgumentError) + params.delete(param) + + expect { test_case }.to raise_error(KeyError) end end - context 'when name is missing' do - let(:params) do - { - classname: 'trace', - file: 'spec/trace_spec.rb', - execution_time: 1.23, - status: described_class::STATUS_SUCCESS, - system_output: nil - } - end + context 'when classname is missing' do + it_behaves_like 'param is missing', :classname + end - it 'raises an error' do - expect { test_case }.to raise_error(ArgumentError) - end + context 'when name is missing' do + it_behaves_like 'param is missing', :name end context 'when attachment is present' do |