diff --git a/spec/tooling/danger/ci_templates_spec.rb b/spec/tooling/danger/ci_templates_spec.rb index b37e7754597545de8f3696e84575aca535595fec..6a6f6825ae630e933f8a40b4c7a429805ef3199f 100644 --- a/spec/tooling/danger/ci_templates_spec.rb +++ b/spec/tooling/danger/ci_templates_spec.rb @@ -12,29 +12,49 @@ let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } - before do - allow(fake_helper).to receive(:ci?).and_return(ci_env) - end - describe '#check!' do - context 'when not in ci environment' do - let(:ci_env) { false } + context 'when checking for mr labels' do + context 'when mr does not have a ci::templates label' do + it 'does not add the danger message, markdown and warning' do + expect(ci_templates).not_to receive(:message) + expect(ci_templates).not_to receive(:markdown) + expect(ci_templates).not_to receive(:warn) + + ci_templates.check! + end + end - it 'does not add the warnings' do - expect(ci_templates).not_to receive(:message) - expect(ci_templates).not_to receive(:markdown) - expect(ci_templates).not_to receive(:warn) + context 'when mr has a ci::templates label' do + before do + allow(fake_helper).to receive(:mr_labels).and_return(['ci::templates']) + allow(ci_templates).to receive(:message) + allow(ci_templates).to receive(:markdown) + end + + it 'adds the danger message and markdown' do + expect(ci_templates).to receive(:message) + expect(ci_templates).to receive(:markdown) - ci_templates.check! + ci_templates.check! + end end end - context 'when in ci environment' do - let(:ci_env) { true } - let(:modified_files) { %w[lib/gitlab/ci/templates/ci_template.rb] } - let(:fake_changes) { instance_double(Gitlab::Dangerfiles::Changes, files: modified_files) } + context 'when checking for changes to ci templates' do + context 'when there are no updated ci templates' do + it 'does not add the danger message, markdown and warning' do + expect(ci_templates).not_to receive(:message) + expect(ci_templates).not_to receive(:markdown) + expect(ci_templates).not_to receive(:warn) + + ci_templates.check! + end + end context 'when there are updates to the ci templates' do + let(:modified_files) { %w[lib/gitlab/ci/templates/ci_template.rb] } + let(:fake_changes) { instance_double(Gitlab::Dangerfiles::Changes, files: modified_files) } + before do allow(fake_changes).to receive(:by_category).with(:ci_template).and_return(fake_changes) allow(fake_helper).to receive(:changes).and_return(fake_changes) @@ -60,16 +80,6 @@ end end end - - context 'when there are no updated ci templates' do - it 'does not add the danger message, markdown and warning' do - expect(ci_templates).not_to receive(:message) - expect(ci_templates).not_to receive(:markdown) - expect(ci_templates).not_to receive(:warn) - - ci_templates.check! - end - end end end end diff --git a/tooling/danger/ci_templates.rb b/tooling/danger/ci_templates.rb index f682dd37d89283ccc4b89531ebd9808c811f1758..fdd0d2b09c234dae45d2f9a8294021662f594153 100644 --- a/tooling/danger/ci_templates.rb +++ b/tooling/danger/ci_templates.rb @@ -20,8 +20,6 @@ module CiTemplates MSG def check! - return unless helper.ci? - return unless helper.mr_labels.include?('ci::templates') || changes.any? message('This merge request adds or changes files that require a ' \ diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb index dd5ae6be8e563139376e0cf63a56fdad540fff1e..20b408d0506b4ae9fcf8cde4b58bf1537e4dcd5a 100644 --- a/tooling/danger/project_helper.rb +++ b/tooling/danger/project_helper.rb @@ -5,7 +5,6 @@ module Danger module ProjectHelper CI_ONLY_RULES ||= %w[ ce_ee_vue_templates - ci_templates datateam feature_flag roulette