diff options
Diffstat (limited to 'spec/tooling/danger/changelog_spec.rb')
-rw-r--r-- | spec/tooling/danger/changelog_spec.rb | 153 |
1 files changed, 116 insertions, 37 deletions
diff --git a/spec/tooling/danger/changelog_spec.rb b/spec/tooling/danger/changelog_spec.rb index b74039b3cd1..7ea2288fd45 100644 --- a/spec/tooling/danger/changelog_spec.rb +++ b/spec/tooling/danger/changelog_spec.rb @@ -161,23 +161,42 @@ RSpec.describe Tooling::Danger::Changelog do describe '#modified_text' do subject { changelog.modified_text } - context "when title is not changed from sanitization", :aggregate_failures do - let(:mr_title) { 'Fake Title' } + context 'when in CI context' do + shared_examples 'changelog modified text' do |key| + specify do + expect(subject).to include('CHANGELOG.md was edited') + expect(subject).to include('bin/changelog -m 1234 "Fake Title"') + expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + end + end - specify do - expect(subject).to include('CHANGELOG.md was edited') - expect(subject).to include('bin/changelog -m 1234 "Fake Title"') - expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + before do + allow(fake_helper).to receive(:ci?).and_return(true) + end + + context "when title is not changed from sanitization", :aggregate_failures do + let(:mr_title) { 'Fake Title' } + + it_behaves_like 'changelog modified text' + end + + context "when title needs sanitization", :aggregate_failures do + let(:mr_title) { 'DRAFT: Fake Title' } + + it_behaves_like 'changelog modified text' end end - context "when title needs sanitization", :aggregate_failures do - let(:mr_title) { 'DRAFT: Fake Title' } + context 'when in local context' do + let(:mr_title) { 'Fake Title' } + + before do + allow(fake_helper).to receive(:ci?).and_return(false) + end specify do expect(subject).to include('CHANGELOG.md was edited') - expect(subject).to include('bin/changelog -m 1234 "Fake Title"') - expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + expect(subject).not_to include('bin/changelog') end end end @@ -187,56 +206,116 @@ RSpec.describe Tooling::Danger::Changelog do subject { changelog.required_texts } - shared_examples 'changelog required text' do |key| - specify do - expect(subject).to have_key(key) - expect(subject[key]).to include('CHANGELOG missing') - expect(subject[key]).to include('bin/changelog -m 1234 "Fake Title"') - expect(subject[key]).not_to include('--ee') + context 'when in CI context' do + before do + allow(fake_helper).to receive(:ci?).and_return(true) end - end - context 'with a new migration file' do - let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) } + shared_examples 'changelog required text' do |key| + specify do + expect(subject).to have_key(key) + expect(subject[key]).to include('CHANGELOG missing') + expect(subject[key]).to include('bin/changelog -m 1234 "Fake Title"') + expect(subject[key]).not_to include('--ee') + end + end - context "when title is not changed from sanitization", :aggregate_failures do - it_behaves_like 'changelog required text', :db_changes + context 'with a new migration file' do + let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) } + + context "when title is not changed from sanitization", :aggregate_failures do + it_behaves_like 'changelog required text', :db_changes + end + + context "when title needs sanitization", :aggregate_failures do + let(:mr_title) { 'DRAFT: Fake Title' } + + it_behaves_like 'changelog required text', :db_changes + end end - context "when title needs sanitization", :aggregate_failures do - let(:mr_title) { 'DRAFT: Fake Title' } + context 'with a removed feature flag file' do + let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) } - it_behaves_like 'changelog required text', :db_changes + it_behaves_like 'changelog required text', :feature_flag_removed end end - context 'with a removed feature flag file' do - let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) } + context 'when in local context' do + before do + allow(fake_helper).to receive(:ci?).and_return(false) + end + + shared_examples 'changelog required text' do |key| + specify do + expect(subject).to have_key(key) + expect(subject[key]).to include('CHANGELOG missing') + expect(subject[key]).not_to include('bin/changelog') + expect(subject[key]).not_to include('--ee') + end + end + + context 'with a new migration file' do + let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) } + + context "when title is not changed from sanitization", :aggregate_failures do + it_behaves_like 'changelog required text', :db_changes + end + + context "when title needs sanitization", :aggregate_failures do + let(:mr_title) { 'DRAFT: Fake Title' } - it_behaves_like 'changelog required text', :feature_flag_removed + it_behaves_like 'changelog required text', :db_changes + end + end + + context 'with a removed feature flag file' do + let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) } + + it_behaves_like 'changelog required text', :feature_flag_removed + end end end describe '#optional_text' do subject { changelog.optional_text } - context "when title is not changed from sanitization", :aggregate_failures do - let(:mr_title) { 'Fake Title' } + context 'when in CI context' do + shared_examples 'changelog optional text' do |key| + specify do + expect(subject).to include('CHANGELOG missing') + expect(subject).to include('bin/changelog -m 1234 "Fake Title"') + expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + end + end - specify do - expect(subject).to include('CHANGELOG missing') - expect(subject).to include('bin/changelog -m 1234 "Fake Title"') - expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + before do + allow(fake_helper).to receive(:ci?).and_return(true) + end + + context "when title is not changed from sanitization", :aggregate_failures do + let(:mr_title) { 'Fake Title' } + + it_behaves_like 'changelog optional text' + end + + context "when title needs sanitization", :aggregate_failures do + let(:mr_title) { 'DRAFT: Fake Title' } + + it_behaves_like 'changelog optional text' end end - context "when title needs sanitization", :aggregate_failures do - let(:mr_title) { 'DRAFT: Fake Title' } + context 'when in local context' do + let(:mr_title) { 'Fake Title' } + + before do + allow(fake_helper).to receive(:ci?).and_return(false) + end specify do expect(subject).to include('CHANGELOG missing') - expect(subject).to include('bin/changelog -m 1234 "Fake Title"') - expect(subject).to include('bin/changelog --ee -m 1234 "Fake Title"') + expect(subject).not_to include('bin/changelog') end end end |