summaryrefslogtreecommitdiff
path: root/spec/tooling/danger/product_intelligence_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tooling/danger/product_intelligence_spec.rb')
-rw-r--r--spec/tooling/danger/product_intelligence_spec.rb103
1 files changed, 69 insertions, 34 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