diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-17 03:12:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-17 03:12:37 +0300 |
commit | 049fd8333a1c87144f43680f69f472de89bb7743 (patch) | |
tree | f04a0c0dc4aa142a46ac7544c9decc8af9083764 /spec/tooling/danger | |
parent | f9e0126cad562c7199e26e84a1540df3bc849e55 (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 | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index 24da0ee1047..ec475df6d83 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -7,8 +7,10 @@ require 'danger/plugins/helper' require 'gitlab/dangerfiles/spec_helper' require_relative '../../../danger/plugins/project_helper' +require_relative '../../../spec/support/helpers/stub_env' RSpec.describe Tooling::Danger::ProjectHelper do + include StubENV include_context "with dangerfile" let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } @@ -341,6 +343,70 @@ RSpec.describe Tooling::Danger::ProjectHelper do 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 } |