Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-02 09:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-02 09:09:24 +0300
commit8bf623d6eaa873c2a77da3c14b51ce1eabdc84f7 (patch)
treea42c566ca98ae0eee3201994860ba31fe46bc45f /spec/rubocop
parent123582839259a70910bd0e9109e57ed65d71cb23 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/experiments_test_coverage_spec.rb169
1 files changed, 169 insertions, 0 deletions
diff --git a/spec/rubocop/cop/experiments_test_coverage_spec.rb b/spec/rubocop/cop/experiments_test_coverage_spec.rb
new file mode 100644
index 00000000000..eb1e672ef40
--- /dev/null
+++ b/spec/rubocop/cop/experiments_test_coverage_spec.rb
@@ -0,0 +1,169 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+
+require_relative '../../../rubocop/cop/experiments_test_coverage'
+
+RSpec.describe RuboCop::Cop::ExperimentsTestCoverage, feature_category: :experimentation_conversion do
+ let(:class_offense) { described_class::CLASS_OFFENSE }
+ let(:block_offense) { described_class::BLOCK_OFFENSE }
+
+ before do
+ allow(File).to receive(:exist?).and_return(true)
+ allow(File).to receive(:new).and_return(instance_double(File, read: tests_code))
+ end
+
+ describe '#on_class' do
+ context 'when there are no tests' do
+ let(:tests_code) { '' }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ class ExperimentName < ApplicationExperiment
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{class_offense}
+ end
+ RUBY
+ end
+ end
+
+ context 'when there is no stub_experiments' do
+ let(:tests_code) { "candidate third" }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ class ExperimentName < ApplicationExperiment
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{class_offense}
+ candidate
+ variant(:third) { 'third option' }
+ end
+ RUBY
+ end
+ end
+
+ context 'when variant test is missing' do
+ let(:tests_code) { "\nstub_experiments(experiment_name: :candidate)" }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ class ExperimentName < ApplicationExperiment
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{class_offense}
+ candidate
+ variant(:third) { 'third option' }
+ end
+ RUBY
+ end
+ end
+
+ context 'when stub_experiments is commented out' do
+ let(:tests_code) do
+ "\n# stub_experiments(experiment_name: :candidate, experiment_name: :third)"
+ end
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ class ExperimentName < ApplicationExperiment
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{class_offense}
+ candidate
+ variant(:third) { 'third option' }
+ end
+ RUBY
+ end
+ end
+
+ context 'when all tests are present' do
+ let(:tests_code) do
+ "#\nstub_experiments(experiment_name: :candidate, experiment_name: :third)"
+ end
+
+ before do
+ allow(cop).to receive(:filepath).and_return('app/experiments/experiment_name_experiment.rb')
+ end
+
+ it 'does not register an offense' do
+ expect_no_offenses(<<~RUBY)
+ class ExperimentName < ApplicationExperiment
+ candidate
+ variant(:third) { 'third option' }
+ end
+ RUBY
+ end
+ end
+ end
+
+ describe '#on_block' do
+ context 'when there are no tests' do
+ let(:tests_code) { '' }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ experiment(:experiment_name) do |e|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{block_offense}
+ end
+ RUBY
+ end
+ end
+
+ context 'when there is no stub_experiments' do
+ let(:tests_code) { "candidate third" }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ experiment(:experiment_name) do |e|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{block_offense}
+ e.candidate { 'candidate' }
+ e.variant(:third) { 'third option' }
+ e.run
+ end
+ RUBY
+ end
+ end
+
+ context 'when variant test is missing' do
+ let(:tests_code) { "\nstub_experiments(experiment_name: :candidate)" }
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ experiment(:experiment_name) do |e|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{block_offense}
+ e.candidate { 'candidate' }
+ e.variant(:third) { 'third option' }
+ e.run
+ end
+ RUBY
+ end
+ end
+
+ context 'when stub_experiments is commented out' do
+ let(:tests_code) do
+ "\n# stub_experiments(experiment_name: :candidate, experiment_name: :third)"
+ end
+
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ experiment(:experiment_name) do |e|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{block_offense}
+ e.candidate { 'candidate' }
+ e.variant(:third) { 'third option' }
+ e.run
+ end
+ RUBY
+ end
+ end
+
+ context 'when all tests are present' do
+ let(:tests_code) do
+ "#\nstub_experiments(experiment_name: :candidate, experiment_name: :third)"
+ end
+
+ it 'does not register an offense' do
+ expect_no_offenses(<<~RUBY)
+ experiment(:experiment_name) do |e|
+ e.candidate { 'candidate' }
+ e.variant(:third) { 'third option' }
+ e.run
+ end
+ RUBY
+ end
+ end
+ end
+end