diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /qa/spec/specs | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'qa/spec/specs')
-rw-r--r-- | qa/spec/specs/allure_report_spec.rb | 93 | ||||
-rw-r--r-- | qa/spec/specs/helpers/context_selector_spec.rb | 28 | ||||
-rw-r--r-- | qa/spec/specs/helpers/quarantine_spec.rb | 28 |
3 files changed, 109 insertions, 40 deletions
diff --git a/qa/spec/specs/allure_report_spec.rb b/qa/spec/specs/allure_report_spec.rb new file mode 100644 index 00000000000..27bc0dd3d1d --- /dev/null +++ b/qa/spec/specs/allure_report_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'allure-rspec' + +describe QA::Runtime::AllureReport do + include Helpers::StubENV + + let(:rspec_config) { double('RSpec::Core::Configuration', 'add_formatter': nil, after: nil) } + + let(:png_path) { 'png_path' } + let(:html_path) { 'html_path' } + + let(:allure_config) do + # need to mock config in case the test itself is executed with allure reporting enabled + AllureRspec::RspecConfig.send(:new).tap do |conf| + conf.instance_variable_set(:@allure_config, Allure::Config.send(:new)) + end + end + + before do + stub_env('QA_GENERATE_ALLURE_REPORT', generate_report) + + allow(AllureRspec).to receive(:configure).and_yield(allure_config) + allow(RSpec).to receive(:configure).and_yield(rspec_config) + allow(Capybara::Screenshot).to receive(:after_save_screenshot).and_yield(png_path) + allow(Capybara::Screenshot).to receive(:after_save_html).and_yield(html_path) + end + + context 'with report generation disabled' do + let(:generate_report) { 'false' } + + it 'does not perform configuration' do + aggregate_failures do + expect(described_class.configure!).to be_nil + + expect(AllureRspec).not_to have_received(:configure) + expect(RSpec).not_to have_received(:configure) + expect(Capybara::Screenshot).not_to have_received(:after_save_screenshot) + expect(Capybara::Screenshot).not_to have_received(:after_save_html) + end + end + end + + context 'with report generation enabled' do + let(:generate_report) { 'true' } + + let(:png_file) { 'png-file' } + let(:html_file) { 'html-file' } + let(:ci_job) { 'ee:relative 5' } + + before do + stub_env('CI', 'true') + stub_env('CI_JOB_NAME', ci_job) + + allow(Allure).to receive(:add_attachment) + allow(File).to receive(:open).with(png_path) { png_file } + allow(File).to receive(:open).with(html_path) { html_file } + + described_class.configure! + end + + it 'configures Allure options' do + aggregate_failures do + expect(allure_config.results_directory).to eq('tmp/allure-results') + expect(allure_config.clean_results_directory).to eq(true) + expect(allure_config.environment_properties).to be_a_kind_of(Hash) + expect(allure_config.environment).to eq('ee:relative') + end + end + + it 'adds rspec and metadata formatter' do + expect(rspec_config).to have_received(:add_formatter).with(AllureRspecFormatter).ordered + expect(rspec_config).to have_received(:add_formatter).with(QA::Support::AllureMetadataFormatter).ordered + end + + it 'configures screenshot saving' do + aggregate_failures do + expect(Allure).to have_received(:add_attachment).with( + name: 'screenshot', + source: png_file, + type: Allure::ContentType::PNG, + test_case: true + ) + expect(Allure).to have_received(:add_attachment).with( + name: 'html', + source: html_file, + type: 'text/html', + test_case: true + ) + end + end + end +end diff --git a/qa/spec/specs/helpers/context_selector_spec.rb b/qa/spec/specs/helpers/context_selector_spec.rb index f0250103008..cbdbe6698ae 100644 --- a/qa/spec/specs/helpers/context_selector_spec.rb +++ b/qa/spec/specs/helpers/context_selector_spec.rb @@ -2,29 +2,25 @@ require 'rspec/core/sandbox' -RSpec.configure do |c| - c.around do |ex| +RSpec.describe QA::Specs::Helpers::ContextSelector do + include Helpers::StubENV + include QA::Specs::Helpers::RSpec + + around do |ex| + QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com') + RSpec::Core::Sandbox.sandboxed do |config| + config.formatter = QA::Specs::Helpers::ContextFormatter + # If there is an example-within-an-example, we want to make sure the inner example # does not get a reference to the outer example (the real spec) if it calls # something like `pending` config.before(:context) { RSpec.current_example = nil } - config.color_mode = :off ex.run end end -end - -RSpec.describe QA::Specs::Helpers::ContextSelector do - include Helpers::StubENV - include QA::Specs::Helpers::RSpec - - before do - QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com') - described_class.configure_rspec - end describe '.context_matches?' do it 'returns true when url has .com' do @@ -104,7 +100,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'with different environment set' do before do QA::Runtime::Scenario.define(:gitlab_address, 'https://gitlab.com') - described_class.configure_rspec end it 'does not run against production' do @@ -239,7 +234,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'without CI_PROJECT_NAME set' do before do stub_env('CI_PROJECT_NAME', nil) - described_class.configure_rspec end it 'runs on any pipeline' do @@ -273,7 +267,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'when a pipeline triggered from the default branch runs in gitlab-qa' do before do stub_env('CI_PROJECT_NAME', 'gitlab-qa') - described_class.configure_rspec end it 'runs on default branch pipelines' do @@ -310,7 +303,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'with CI_PROJECT_NAME set' do before do stub_env('CI_PROJECT_NAME', 'NIGHTLY') - described_class.configure_rspec end it 'runs on designated pipeline' do @@ -353,7 +345,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'without CI_JOB_NAME set' do before do stub_env('CI_JOB_NAME', nil) - described_class.configure_rspec end context 'when excluding contexts' do @@ -396,7 +387,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do context 'with CI_JOB_NAME set' do before do stub_env('CI_JOB_NAME', 'ee:instance-image') - described_class.configure_rspec end context 'when excluding contexts' do diff --git a/qa/spec/specs/helpers/quarantine_spec.rb b/qa/spec/specs/helpers/quarantine_spec.rb index 45754a09b17..548a8510988 100644 --- a/qa/spec/specs/helpers/quarantine_spec.rb +++ b/qa/spec/specs/helpers/quarantine_spec.rb @@ -2,9 +2,14 @@ require 'rspec/core/sandbox' -RSpec.configure do |c| - c.around do |ex| +RSpec.describe QA::Specs::Helpers::Quarantine do + include Helpers::StubENV + include QA::Specs::Helpers::RSpec + + around do |ex| RSpec::Core::Sandbox.sandboxed do |config| + config.formatter = QA::Specs::Helpers::QuarantineFormatter + # If there is an example-within-an-example, we want to make sure the inner example # does not get a reference to the outer example (the real spec) if it calls # something like `pending` @@ -15,18 +20,9 @@ RSpec.configure do |c| ex.run end end -end - -RSpec.describe QA::Specs::Helpers::Quarantine do - include Helpers::StubENV - include QA::Specs::Helpers::RSpec describe '.skip_or_run_quarantined_contexts' do context 'with no tag focused' do - before do - described_class.configure_rspec - end - it 'skips before hooks of quarantined contexts' do executed_hooks = [] @@ -66,7 +62,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do context 'with :quarantine focused' do before do - described_class.configure_rspec RSpec.configure do |c| c.filter_run :quarantine end @@ -110,10 +105,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do describe '.skip_or_run_quarantined_tests_or_contexts' do context 'with no tag focused' do - before do - described_class.configure_rspec - end - it 'skips quarantined tests' do group = describe_successfully do it('is pending', :quarantine) {} @@ -135,7 +126,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do context 'with environment set' do before do QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com') - described_class.configure_rspec end context 'no pipeline specified' do @@ -168,7 +158,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do shared_examples 'skipped in project' do |project| before do stub_env('CI_PROJECT_NAME', project) - described_class.configure_rspec end it "is skipped in #{project}" do @@ -209,7 +198,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do context 'with :quarantine focused' do before do - described_class.configure_rspec RSpec.configure do |c| c.filter_run :quarantine end @@ -234,7 +222,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do context 'with a non-quarantine tag focused' do before do - described_class.configure_rspec RSpec.configure do |c| c.filter_run :foo end @@ -277,7 +264,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do context 'with :quarantine and non-quarantine tags focused' do before do - described_class.configure_rspec RSpec.configure do |c| c.filter_run :foo, :bar, :quarantine end |