diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 18:10:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 18:10:36 +0300 |
commit | 78aaabb87f180e93fa53aba407a0eef1e12a7a56 (patch) | |
tree | 6072c319e481f75960853c557578a5d04315b1fe /spec/tooling/danger | |
parent | 5f0d27d131aced1a53e8cbc7db023d9f947f8a1a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tooling/danger')
-rw-r--r-- | spec/tooling/danger/project_helper_spec.rb | 105 | ||||
-rw-r--r-- | spec/tooling/danger/specs_spec.rb | 2 |
2 files changed, 6 insertions, 101 deletions
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index 2749a7733de..f13083bdf0a 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -3,7 +3,7 @@ require 'rspec-parameterized' require 'gitlab-dangerfiles' require 'danger' -require 'danger/plugins/helper' +require 'danger/plugins/internal/helper' require 'gitlab/dangerfiles/spec_helper' require_relative '../../../danger/plugins/project_helper' @@ -20,22 +20,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do before do allow(project_helper).to receive(:helper).and_return(fake_helper) - end - - describe '#changes' do - it 'returns an array of Change objects' do - expect(project_helper.changes).to all(be_an(Gitlab::Dangerfiles::Change)) - end - - it 'groups changes by change type' do - changes = project_helper.changes - - expect(changes.added.files).to eq(added_files) - expect(changes.modified.files).to eq(modified_files) - expect(changes.deleted.files).to eq(deleted_files) - expect(changes.renamed_before.files).to eq([renamed_before_file]) - expect(changes.renamed_after.files).to eq([renamed_after_file]) - end + allow(fake_helper).to receive(:config).and_return(double(files_to_category: described_class::CATEGORIES)) end describe '#categories_for_file' do @@ -247,7 +232,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do end with_them do - subject { project_helper.categories_for_file(path) } + subject { project_helper.helper.categories_for_file(path) } it { is_expected.to eq(expected_categories) } end @@ -275,7 +260,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do changed_files.each do |file| allow(fake_git).to receive(:diff_for_file).with(file) { double(:diff, patch: patch) } - expect(project_helper.categories_for_file(file)).to eq(expected_categories) + expect(project_helper.helper.categories_for_file(file)).to eq(expected_categories) end end end @@ -321,93 +306,13 @@ RSpec.describe Tooling::Danger::ProjectHelper do it 'returns all changed files starting with ee/' do changes = double - expect(project_helper).to receive(:changes).and_return(changes) + expect(fake_helper).to receive(:changes).and_return(changes) expect(changes).to receive(:files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k]) is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb]) end end - describe '#project_name' do - subject { project_helper.project_name } - - it 'returns gitlab if ee? returns true' do - expect(project_helper).to receive(:ee?) { true } - - is_expected.to eq('gitlab') - end - - it 'returns gitlab-ce if ee? returns false' do - expect(project_helper).to receive(:ee?) { false } - - is_expected.to eq('gitlab-foss') - end - end - - describe '#ee?' do - subject { project_helper.__send__(:ee?) } - - let(:ee_dir) { File.expand_path('../../../ee', __dir__) } - - context 'when ENV["CI_PROJECT_NAME"] is set' do - before do - stub_env('CI_PROJECT_NAME', ci_project_name) - end - - context 'when ENV["CI_PROJECT_NAME"] is gitlab' do - let(:ci_project_name) { 'gitlab' } - - it 'returns true' do - is_expected.to eq(true) - end - end - - context 'when ENV["CI_PROJECT_NAME"] is gitlab-ee' do - let(:ci_project_name) { 'gitlab-ee' } - - it 'returns true' do - is_expected.to eq(true) - end - end - - context 'when ENV["CI_PROJECT_NAME"] is gitlab-foss' do - let(:ci_project_name) { 'gitlab-foss' } - - it 'resolves to Dir.exist?' do - expected = Dir.exist?(ee_dir) - - expect(Dir).to receive(:exist?).with(ee_dir).and_call_original - - is_expected.to eq(expected) - end - end - end - - context 'when ENV["CI_PROJECT_NAME"] is absent' do - before do - stub_env('CI_PROJECT_NAME', nil) - - expect(Dir).to receive(:exist?).with(ee_dir).and_return(has_ee_dir) - end - - context 'when ee/ directory exists' do - let(:has_ee_dir) { true } - - it 'returns true' do - is_expected.to eq(true) - end - end - - context 'when ee/ directory does not exist' do - let(:has_ee_dir) { false } - - it 'returns false' do - is_expected.to eq(false) - end - end - end - end - describe '#file_lines' do let(:filename) { 'spec/foo_spec.rb' } let(:file_spy) { spy } diff --git a/spec/tooling/danger/specs_spec.rb b/spec/tooling/danger/specs_spec.rb index a5978020c9d..b2454960a7b 100644 --- a/spec/tooling/danger/specs_spec.rb +++ b/spec/tooling/danger/specs_spec.rb @@ -3,7 +3,7 @@ require 'rspec-parameterized' require 'gitlab-dangerfiles' require 'danger' -require 'danger/plugins/helper' +require 'danger/plugins/internal/helper' require 'gitlab/dangerfiles/spec_helper' require_relative '../../../tooling/danger/specs' |