Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/scripts/failed_tests_spec.rb')
-rw-r--r--spec/scripts/failed_tests_spec.rb200
1 files changed, 96 insertions, 104 deletions
diff --git a/spec/scripts/failed_tests_spec.rb b/spec/scripts/failed_tests_spec.rb
index b99fd991c55..ce0ec66cdb6 100644
--- a/spec/scripts/failed_tests_spec.rb
+++ b/spec/scripts/failed_tests_spec.rb
@@ -5,121 +5,113 @@ 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
+ let(:options) { described_class::DEFAULT_OPTIONS.merge(previous_tests_report_path: report_file) }
+ 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
- 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
+ subject { described_class.new(options) }
+
+ describe '#output_failed_tests' do
+ context 'with a valid report file' do
+ before do
+ allow(subject).to receive(:file_contents_as_json).and_return(file_contents_as_json)
+ end
+
+ it 'writes the file for the suite' do
+ expect(File).to receive(:open)
+ .with(File.join(described_class::DEFAULT_OPTIONS[:output_directory], "rspec_failed_tests.txt"), 'w').once
+ expect(File).to receive(:open)
+ .with(File.join(described_class::DEFAULT_OPTIONS[:output_directory], "rspec_ee_failed_tests.txt"), 'w').once
+
+ subject.output_failed_tests
+ end
+
+ context 'when given a valid format' do
+ subject { described_class.new(options.merge(format: :json)) }
+
+ it 'writes the file for the suite' do
+ expect(File).to receive(:open)
+ .with(File.join(described_class::DEFAULT_OPTIONS[:output_directory], "rspec_failed_tests.json"), 'w').once
+ expect(File).to receive(:open)
+ .with(File.join(described_class::DEFAULT_OPTIONS[:output_directory], "rspec_ee_failed_tests.json"), 'w')
+ .once
+
+ subject.output_failed_tests
+ end
+ end
+
+ context 'when given an invalid format' do
+ subject { described_class.new(options.merge(format: :foo)) }
+
+ it 'raises an exception' do
+ expect { subject.output_failed_tests }
+ .to raise_error '[FailedTests] Unsupported format `foo` (allowed formats: `oneline` and `json`)!'
+ end
+ end
+
+ describe 'empty report' do
+ let(:file_contents_as_json) do
+ {}
+ end
+
+ it 'does not fail for output files' do
+ subject.output_failed_tests
+ end
+
+ it 'returns empty results for suite failures' do
+ result = subject.failed_cases_for_suite_collection
+
+ expect(result.values.flatten).to be_empty
+ end
+ end
end
end
describe 'missing report file' do
- let(:report_file) { 'unknownfile.json' }
+ subject { described_class.new(options.merge(previous_tests_report_path: 'unknownfile.json')) }
it 'does not fail for output files' do
- subject.output_failed_test_files
+ subject.output_failed_tests
end
it 'returns empty results for suite failures' do
- result = subject.failed_files_for_suite_collection
+ result = subject.failed_cases_for_suite_collection
expect(result.values.flatten).to be_empty
end