summaryrefslogtreecommitdiff
path: root/spec/tooling
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /spec/tooling
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/tooling')
-rw-r--r--spec/tooling/danger/product_intelligence_spec.rb10
-rw-r--r--spec/tooling/danger/project_helper_spec.rb16
-rw-r--r--spec/tooling/danger/specs_spec.rb133
-rw-r--r--spec/tooling/quality/test_level_spec.rb18
4 files changed, 174 insertions, 3 deletions
diff --git a/spec/tooling/danger/product_intelligence_spec.rb b/spec/tooling/danger/product_intelligence_spec.rb
index 4ab911b6590..5fd44ef5de0 100644
--- a/spec/tooling/danger/product_intelligence_spec.rb
+++ b/spec/tooling/danger/product_intelligence_spec.rb
@@ -59,6 +59,14 @@ RSpec.describe Tooling::Danger::ProductIntelligence do
it { is_expected.to be_empty }
end
+
+ context 'with growth experiment label' do
+ before do
+ allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(true)
+ end
+
+ it { is_expected.to be_empty }
+ end
end
describe '#matching_changed_files' do
@@ -74,7 +82,7 @@ RSpec.describe Tooling::Danger::ProductIntelligence do
context 'with snowplow files changed' do
context 'when vue file changed' do
- let(:changed_lines) { ['+data-track-event'] }
+ let(:changed_lines) { ['+data-track-action'] }
it { is_expected.to match_array(['components/welcome.vue']) }
end
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb
index c7715eb43fc..5edd9e54cc5 100644
--- a/spec/tooling/danger/project_helper_spec.rb
+++ b/spec/tooling/danger/project_helper_spec.rb
@@ -93,6 +93,9 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'ee/spec/foo' | [:backend]
'ee/spec/foo/bar' | [:backend]
+ 'spec/migrations/foo' | [:database]
+ 'ee/spec/migrations/foo' | [:database]
+
'spec/features/foo' | [:test]
'ee/spec/features/foo' | [:test]
'spec/support/shared_examples/features/foo' | [:test]
@@ -277,4 +280,17 @@ RSpec.describe Tooling::Danger::ProjectHelper do
is_expected.to eq('gitlab-foss')
end
end
+
+ describe '#file_lines' do
+ let(:filename) { 'spec/foo_spec.rb' }
+ let(:file_spy) { spy }
+
+ it 'returns the chomped file lines' do
+ expect(project_helper).to receive(:read_file).with(filename).and_return(file_spy)
+
+ project_helper.file_lines(filename)
+
+ expect(file_spy).to have_received(:lines).with(chomp: true)
+ end
+ end
end
diff --git a/spec/tooling/danger/specs_spec.rb b/spec/tooling/danger/specs_spec.rb
new file mode 100644
index 00000000000..a5978020c9d
--- /dev/null
+++ b/spec/tooling/danger/specs_spec.rb
@@ -0,0 +1,133 @@
+# frozen_string_literal: true
+
+require 'rspec-parameterized'
+require 'gitlab-dangerfiles'
+require 'danger'
+require 'danger/plugins/helper'
+require 'gitlab/dangerfiles/spec_helper'
+
+require_relative '../../../tooling/danger/specs'
+require_relative '../../../tooling/danger/project_helper'
+
+RSpec.describe Tooling::Danger::Specs do
+ include_context "with dangerfile"
+
+ let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
+ let(:fake_project_helper) { double('fake-project-helper', helper: fake_helper).tap { |h| h.class.include(Tooling::Danger::ProjectHelper) } }
+ let(:file_lines) do
+ [
+ " describe 'foo' do",
+ " expect(foo).to match(['bar'])",
+ " end",
+ " expect(foo).to match(['bar'])", # same line as line 1 above, we expect two different suggestions
+ " ",
+ " expect(foo).to match ['bar']",
+ " expect(foo).to eq(['bar'])",
+ " expect(foo).to eq ['bar']",
+ " expect(foo).to(match(['bar']))",
+ " expect(foo).to(eq(['bar']))",
+ " foo.eq(['bar'])"
+ ]
+ end
+
+ let(:matching_lines) do
+ [
+ "+ expect(foo).to match(['bar'])",
+ "+ expect(foo).to match(['bar'])",
+ "+ expect(foo).to match ['bar']",
+ "+ expect(foo).to eq(['bar'])",
+ "+ expect(foo).to eq ['bar']",
+ "+ expect(foo).to(match(['bar']))",
+ "+ expect(foo).to(eq(['bar']))"
+ ]
+ end
+
+ subject(:specs) { fake_danger.new(helper: fake_helper) }
+
+ before do
+ allow(specs).to receive(:project_helper).and_return(fake_project_helper)
+ end
+
+ describe '#add_suggestions_for_match_with_array' do
+ let(:filename) { 'spec/foo_spec.rb' }
+
+ before do
+ expect(specs).to receive(:added_line_matching_match_with_array).and_return(matching_lines)
+ allow(specs.project_helper).to receive(:file_lines).and_return(file_lines)
+ end
+
+ it 'adds suggestions at the correct lines' do
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to match_array(['bar'])"), file: filename, line: 2)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to match_array(['bar'])"), file: filename, line: 4)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to match_array ['bar']"), file: filename, line: 6)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to match_array(['bar'])"), file: filename, line: 7)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to match_array ['bar']"), file: filename, line: 8)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to(match_array(['bar']))"), file: filename, line: 9)
+ expect(specs).to receive(:markdown).with(format(described_class::SUGGEST_MR_COMMENT, suggested_line: " expect(foo).to(match_array(['bar']))"), file: filename, line: 10)
+
+ specs.add_suggestions_for_match_with_array(filename)
+ end
+ end
+
+ describe '#changed_specs_files' do
+ let(:base_expected_files) { %w[spec/foo_spec.rb ee/spec/foo_spec.rb spec/bar_spec.rb ee/spec/bar_spec.rb spec/zab_spec.rb ee/spec/zab_spec.rb] }
+
+ before do
+ all_changed_files = %w[
+ app/workers/a.rb
+ app/workers/b.rb
+ app/workers/e.rb
+ spec/foo_spec.rb
+ ee/spec/foo_spec.rb
+ spec/bar_spec.rb
+ ee/spec/bar_spec.rb
+ spec/zab_spec.rb
+ ee/spec/zab_spec.rb
+ ]
+
+ allow(specs.helper).to receive(:all_changed_files).and_return(all_changed_files)
+ end
+
+ it 'returns added, modified, and renamed_after files by default' do
+ expect(specs.changed_specs_files).to match_array(base_expected_files)
+ end
+
+ context 'with include_ee: :exclude' do
+ it 'returns spec files without EE-specific files' do
+ expect(specs.changed_specs_files(ee: :exclude)).not_to include(%w[ee/spec/foo_spec.rb ee/spec/bar_spec.rb ee/spec/zab_spec.rb])
+ end
+ end
+
+ context 'with include_ee: :only' do
+ it 'returns EE-specific spec files only' do
+ expect(specs.changed_specs_files(ee: :only)).to match_array(%w[ee/spec/foo_spec.rb ee/spec/bar_spec.rb ee/spec/zab_spec.rb])
+ end
+ end
+ end
+
+ describe '#added_line_matching_match_with_array' do
+ let(:filename) { 'spec/foo_spec.rb' }
+ let(:changed_lines) do
+ [
+ " expect(foo).to match(['bar'])",
+ " expect(foo).to match(['bar'])",
+ " expect(foo).to match ['bar']",
+ " expect(foo).to eq(['bar'])",
+ " expect(foo).to eq ['bar']",
+ "- expect(foo).to match(['bar'])",
+ "- expect(foo).to match(['bar'])",
+ "- expect(foo).to match ['bar']",
+ "- expect(foo).to eq(['bar'])",
+ "- expect(foo).to eq ['bar']"
+ ] + matching_lines
+ end
+
+ before do
+ allow(specs.helper).to receive(:changed_lines).with(filename).and_return(changed_lines)
+ end
+
+ it 'returns added, modified, and renamed_after files by default' do
+ expect(specs.added_line_matching_match_with_array(filename)).to match_array(matching_lines)
+ end
+ end
+end
diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb
index 89abe337347..0623a67a60e 100644
--- a/spec/tooling/quality/test_level_spec.rb
+++ b/spec/tooling/quality/test_level_spec.rb
@@ -63,7 +63,14 @@ RSpec.describe Quality::TestLevel do
context 'with a prefix' do
it 'returns a pattern' do
expect(described_class.new('ee/').pattern(:system))
- .to eq("ee/spec/{features}{,/**/}*_spec.rb")
+ .to eq("{ee/}spec/{features}{,/**/}*_spec.rb")
+ end
+ end
+
+ context 'with several prefixes' do
+ it 'returns a pattern' do
+ expect(described_class.new(['', 'ee/', 'jh/']).pattern(:system))
+ .to eq("{,ee/,jh/}spec/{features}{,/**/}*_spec.rb")
end
end
@@ -138,7 +145,14 @@ RSpec.describe Quality::TestLevel do
context 'with a prefix' do
it 'returns a regexp' do
expect(described_class.new('ee/').regexp(:system))
- .to eq(%r{ee/spec/(features)})
+ .to eq(%r{(ee/)spec/(features)})
+ end
+ end
+
+ context 'with several prefixes' do
+ it 'returns a regexp' do
+ expect(described_class.new(['', 'ee/', 'jh/']).regexp(:system))
+ .to eq(%r{(|ee/|jh/)spec/(features)})
end
end