summaryrefslogtreecommitdiff
path: root/spec/scripts/failed_tests_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/scripts/failed_tests_spec.rb
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/scripts/failed_tests_spec.rb')
-rw-r--r--spec/scripts/failed_tests_spec.rb127
1 files changed, 127 insertions, 0 deletions
diff --git a/spec/scripts/failed_tests_spec.rb b/spec/scripts/failed_tests_spec.rb
new file mode 100644
index 00000000000..92eae75b3be
--- /dev/null
+++ b/spec/scripts/failed_tests_spec.rb
@@ -0,0 +1,127 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_relative '../../scripts/failed_tests'
+
+RSpec.describe FailedTests do
+ let(:report_file) { 'spec/fixtures/scripts/test_report.json' }
+ let(:output_directory) { 'tmp/previous_test_results' }
+ let(:rspec_pg_regex) { /rspec .+ pg12( .+)?/ }
+ let(:rspec_ee_pg_regex) { /rspec-ee .+ pg12( .+)?/ }
+
+ subject { described_class.new(previous_tests_report_path: report_file, output_directory: output_directory, rspec_pg_regex: rspec_pg_regex, rspec_ee_pg_regex: rspec_ee_pg_regex) }
+
+ describe '#output_failed_test_files' do
+ it 'writes the file for the suite' do
+ expect(File).to receive(:open).with(File.join(output_directory, "rspec_failed_files.txt"), 'w').once
+
+ subject.output_failed_test_files
+ end
+ end
+
+ describe '#failed_files_for_suite_collection' do
+ let(:failure_path) { 'path/to/fail_file_spec.rb' }
+ let(:other_failure_path) { 'path/to/fail_file_spec_2.rb' }
+ let(:file_contents_as_json) do
+ {
+ 'suites' => [
+ {
+ 'failed_count' => 1,
+ 'name' => 'rspec unit pg12 10/12',
+ 'test_cases' => [
+ {
+ 'status' => 'failed',
+ 'file' => failure_path
+ }
+ ]
+ },
+ {
+ 'failed_count' => 1,
+ 'name' => 'rspec-ee unit pg12',
+ 'test_cases' => [
+ {
+ 'status' => 'failed',
+ 'file' => failure_path
+ }
+ ]
+ },
+ {
+ 'failed_count' => 1,
+ 'name' => 'rspec unit pg13 10/12',
+ 'test_cases' => [
+ {
+ 'status' => 'failed',
+ 'file' => other_failure_path
+ }
+ ]
+ }
+ ]
+ }
+ end
+
+ before do
+ allow(subject).to receive(:file_contents_as_json).and_return(file_contents_as_json)
+ end
+
+ it 'returns a list of failed file paths for suite collection' do
+ result = subject.failed_files_for_suite_collection
+
+ expect(result[:rspec].to_a).to match_array(failure_path)
+ expect(result[:rspec_ee].to_a).to match_array(failure_path)
+ end
+ end
+
+ describe 'empty report' do
+ let(:file_content) do
+ '{}'
+ end
+
+ before do
+ allow(subject).to receive(:file_contents).and_return(file_content)
+ end
+
+ it 'does not fail for output files' do
+ subject.output_failed_test_files
+ end
+
+ it 'returns empty results for suite failures' do
+ result = subject.failed_files_for_suite_collection
+
+ expect(result.values.flatten).to be_empty
+ end
+ end
+
+ describe 'invalid report' do
+ let(:file_content) do
+ ''
+ end
+
+ before do
+ allow(subject).to receive(:file_contents).and_return(file_content)
+ end
+
+ it 'does not fail for output files' do
+ subject.output_failed_test_files
+ end
+
+ it 'returns empty results for suite failures' do
+ result = subject.failed_files_for_suite_collection
+
+ expect(result.values.flatten).to be_empty
+ end
+ end
+
+ describe 'missing report file' do
+ let(:report_file) { 'unknownfile.json' }
+
+ it 'does not fail for output files' do
+ subject.output_failed_test_files
+ end
+
+ it 'returns empty results for suite failures' do
+ result = subject.failed_files_for_suite_collection
+
+ expect(result.values.flatten).to be_empty
+ end
+ end
+end