diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-10 06:10:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-10 06:10:11 +0300 |
commit | f2c0afdcb5597b226d75cdb043e57f79034b04bb (patch) | |
tree | e763b343cf6739ad2b43b9d086e5cc66e9e9a2e2 /qa/spec | |
parent | 981771279a48c03263e29f3b4f41f54204ea3146 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa/spec')
-rw-r--r-- | qa/spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | qa/spec/specs/allure_report_spec.rb | 36 | ||||
-rw-r--r-- | qa/spec/specs/helpers/context_selector_spec.rb | 28 | ||||
-rw-r--r-- | qa/spec/specs/helpers/quarantine_spec.rb | 28 | ||||
-rw-r--r-- | qa/spec/support/allure_metadata_formatter_spec.rb | 46 |
5 files changed, 68 insertions, 74 deletions
diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb index c4da85d75b0..0df7b94b894 100644 --- a/qa/spec/spec_helper.rb +++ b/qa/spec/spec_helper.rb @@ -26,8 +26,8 @@ Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| requir RSpec.configure do |config| config.include ::Matchers - QA::Specs::Helpers::Quarantine.configure_rspec - QA::Specs::Helpers::ContextSelector.configure_rspec + config.add_formatter QA::Specs::Helpers::ContextFormatter + config.add_formatter QA::Specs::Helpers::QuarantineFormatter config.before do |example| QA::Runtime::Logger.debug("\nStarting test: #{example.full_description}\n") diff --git a/qa/spec/specs/allure_report_spec.rb b/qa/spec/specs/allure_report_spec.rb index 67ae0712260..27bc0dd3d1d 100644 --- a/qa/spec/specs/allure_report_spec.rb +++ b/qa/spec/specs/allure_report_spec.rb @@ -5,21 +5,7 @@ require 'allure-rspec' describe QA::Runtime::AllureReport do include Helpers::StubENV - let(:rspec_config) { double('RSpec::Core::Configuration', 'formatter=': nil, after: nil) } - let(:rspec_example) do - double( - 'RSpec::Core::Example', - tms: nil, - issue: nil, - add_link: nil, - attempts: 0, - file_path: 'file/path/spec.rb', - metadata: { - testcase: 'testcase', - quarantine: { issue: 'issue' } - } - ) - end + let(:rspec_config) { double('RSpec::Core::Configuration', 'add_formatter': nil, after: nil) } let(:png_path) { 'png_path' } let(:html_path) { 'html_path' } @@ -36,7 +22,6 @@ describe QA::Runtime::AllureReport do allow(AllureRspec).to receive(:configure).and_yield(allure_config) allow(RSpec).to receive(:configure).and_yield(rspec_config) - allow(rspec_config).to receive(:after).and_yield(rspec_example) 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 @@ -62,12 +47,10 @@ describe QA::Runtime::AllureReport do let(:png_file) { 'png-file' } let(:html_file) { 'html-file' } let(:ci_job) { 'ee:relative 5' } - let(:ci_job_url) { 'url' } before do stub_env('CI', 'true') stub_env('CI_JOB_NAME', ci_job) - stub_env('CI_JOB_URL', ci_job_url) allow(Allure).to receive(:add_attachment) allow(File).to receive(:open).with(png_path) { png_file } @@ -85,20 +68,9 @@ describe QA::Runtime::AllureReport do end end - it 'adds rspec formatter' do - expect(rspec_config).to have_received(:formatter=).with(AllureRspecFormatter) - end - - it 'configures after block' do - aggregate_failures do - expect(rspec_example).to have_received(:tms).with('Testcase', 'testcase') - expect(rspec_example).to have_received(:issue).with('Quarantine issue', 'issue') - expect(rspec_example).to have_received(:add_link).with(name: "Job(#{ci_job})", url: ci_job_url) - expect(rspec_example).to have_received(:issue).with( - 'Failure issues', - 'https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=spec.rb' - ) - 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 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 diff --git a/qa/spec/support/allure_metadata_formatter_spec.rb b/qa/spec/support/allure_metadata_formatter_spec.rb new file mode 100644 index 00000000000..cb208642716 --- /dev/null +++ b/qa/spec/support/allure_metadata_formatter_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +describe QA::Support::AllureMetadataFormatter do + include Helpers::StubENV + + let(:formatter) { described_class.new(StringIO.new) } + + let(:rspec_example_notification) { double('RSpec::Core::Notifications::ExampleNotification', example: rspec_example) } + let(:rspec_example) do + double( + 'RSpec::Core::Example', + tms: nil, + issue: nil, + add_link: nil, + attempts: 0, + file_path: 'file/path/spec.rb', + metadata: { + testcase: 'testcase', + quarantine: { issue: 'issue' } + } + ) + end + + let(:ci_job) { 'ee:relative 5' } + let(:ci_job_url) { 'url' } + + before do + stub_env('CI', 'true') + stub_env('CI_JOB_NAME', ci_job) + stub_env('CI_JOB_URL', ci_job_url) + end + + it "adds additional data to report" do + formatter.example_started(rspec_example_notification) + + aggregate_failures do + expect(rspec_example).to have_received(:tms).with('Testcase', 'testcase') + expect(rspec_example).to have_received(:issue).with('Quarantine issue', 'issue') + expect(rspec_example).to have_received(:add_link).with(name: "Job(#{ci_job})", url: ci_job_url) + expect(rspec_example).to have_received(:issue).with( + 'Failure issues', + 'https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=spec.rb' + ) + end + end +end |