diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/tooling | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/tooling')
-rw-r--r-- | spec/tooling/danger/product_intelligence_spec.rb | 103 | ||||
-rw-r--r-- | spec/tooling/danger/project_helper_spec.rb | 34 |
2 files changed, 69 insertions, 68 deletions
diff --git a/spec/tooling/danger/product_intelligence_spec.rb b/spec/tooling/danger/product_intelligence_spec.rb index d0d4b8d4df4..ea08e3bc6db 100644 --- a/spec/tooling/danger/product_intelligence_spec.rb +++ b/spec/tooling/danger/product_intelligence_spec.rb @@ -20,70 +20,105 @@ RSpec.describe Tooling::Danger::ProductIntelligence do allow(fake_helper).to receive(:changed_lines).and_return(changed_lines) end - describe '#missing_labels' do - subject { product_intelligence.missing_labels } + describe '#check!' do + subject { product_intelligence.check! } + let(:markdown_formatted_list) { 'markdown formatted list' } + let(:review_pending_label) { 'product intelligence::review pending' } + let(:approved_label) { 'product intelligence::approved' } let(:ci_env) { true } + let(:previous_label_to_add) { 'label_to_add' } + let(:labels_to_add) { [previous_label_to_add] } + let(:has_product_intelligence_label) { true } before do - allow(fake_helper).to receive(:mr_has_labels?).and_return(false) + allow(fake_helper).to receive(:changes_by_category).and_return(product_intelligence: changed_files, database: ['other_files.yml']) allow(fake_helper).to receive(:ci?).and_return(ci_env) + allow(fake_helper).to receive(:mr_has_labels?).with('product intelligence').and_return(has_product_intelligence_label) + allow(fake_helper).to receive(:markdown_list).with(changed_files).and_return(markdown_formatted_list) + allow(fake_helper).to receive(:labels_to_add).and_return(labels_to_add) end - context 'with ci? false' do - let(:ci_env) { false } + shared_examples "doesn't add new labels" do + it "doesn't add new labels" do + subject - it { is_expected.to be_empty } + expect(labels_to_add).to match_array [previous_label_to_add] + end end - context 'with ci? true' do - let(:expected_labels) { ['product intelligence', 'product intelligence::review pending'] } + shared_examples "doesn't add new warnings" do + it "doesn't add new warnings" do + expect(product_intelligence).not_to receive(:warn) - it { is_expected.to match_array(expected_labels) } + subject + end end - context 'with product intelligence label' do - let(:expected_labels) { ['product intelligence::review pending'] } - let(:mr_labels) { [] } + shared_examples 'adds new labels' do + it 'adds new labels' do + subject + + expect(labels_to_add).to match_array [previous_label_to_add, review_pending_label] + end + end + context 'with growth experiment label' do before do - allow(fake_helper).to receive(:mr_has_labels?).with('product intelligence').and_return(true) - allow(fake_helper).to receive(:mr_labels).and_return(mr_labels) + allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(true) end - it { is_expected.to match_array(expected_labels) } + include_examples "doesn't add new labels" + include_examples "doesn't add new warnings" + end + + context 'without growth experiment label' do + before do + allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(false) + end - context 'with product intelligence::review pending' do - let(:mr_labels) { ['product intelligence::review pending'] } + context 'with approved label' do + let(:mr_labels) { [approved_label] } - it { is_expected.to be_empty } + include_examples "doesn't add new labels" + include_examples "doesn't add new warnings" end - context 'with product intelligence::approved' do - let(:mr_labels) { ['product intelligence::approved'] } + context 'without approved label' do + include_examples 'adds new labels' + + it 'warns with proper message' do + expect(product_intelligence).to receive(:warn).with(%r{#{markdown_formatted_list}}) - it { is_expected.to be_empty } + subject + end end - end - end - describe '#skip_review' do - subject { product_intelligence.skip_review? } + context 'with product intelligence::review pending label' do + let(:mr_labels) { ['product intelligence::review pending'] } - context 'with growth experiment label' do - before do - allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(true) + include_examples "doesn't add new labels" end - it { is_expected.to be true } - end + context 'with product intelligence::approved label' do + let(:mr_labels) { ['product intelligence::approved'] } - context 'without growth experiment label' do - before do - allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(false) + include_examples "doesn't add new labels" end - it { is_expected.to be false } + context 'with the product intelligence label' do + let(:has_product_intelligence_label) { true } + + context 'with ci? false' do + let(:ci_env) { false } + + include_examples "doesn't add new labels" + end + + context 'with ci? true' do + include_examples 'adds new labels' + end + end end end end diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index 902e01e2cbd..b3fb592c2e3 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -276,40 +276,6 @@ RSpec.describe Tooling::Danger::ProjectHelper do end end - describe '.local_warning_message' do - it 'returns an informational message with rules that can run' do - expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation, datateam') - end - end - - describe '.success_message' do - it 'returns an informational success message' do - expect(described_class.success_message).to eq('==> No Danger rule violations!') - end - end - - describe '#rule_names' do - context 'when running locally' do - before do - expect(fake_helper).to receive(:ci?).and_return(false) - end - - it 'returns local only rules' do - expect(project_helper.rule_names).to match_array(described_class::LOCAL_RULES) - end - end - - context 'when running under CI' do - before do - expect(fake_helper).to receive(:ci?).and_return(true) - end - - it 'returns all rules' do - expect(project_helper.rule_names).to eq(described_class::LOCAL_RULES | described_class::CI_ONLY_RULES) - end - end - end - describe '#file_lines' do let(:filename) { 'spec/foo_spec.rb' } let(:file_spy) { spy } |