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>2022-10-20 12:40:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/rubocop/cop/gitlab
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/gitlab')
-rw-r--r--spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb2
-rw-r--r--spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb51
-rw-r--r--spec/rubocop/cop/gitlab/no_code_coverage_comment_spec.rb60
-rw-r--r--spec/rubocop/cop/gitlab/service_response_spec.rb41
4 files changed, 124 insertions, 30 deletions
diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
index 9a1639806c8..0a121a495c9 100644
--- a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
+++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
@@ -4,7 +4,7 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location'
-RSpec.describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
+RSpec.describe RuboCop::Cop::Gitlab::DuplicateSpecLocation, type: :rubocop_rspec do
let(:rails_root) { '../../../../' }
def full_path(path)
diff --git a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
index ac7e41dda44..a3c9ae8916e 100644
--- a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
+++ b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
@@ -7,7 +7,7 @@ require_relative '../../../../rubocop/cop/gitlab/mark_used_feature_flags'
RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
let(:defined_feature_flags) do
- %w[a_feature_flag foo_hello foo_world baz_experiment_percentage bar_baz]
+ %w[a_feature_flag foo_hello foo_world bar_baz baz]
end
before do
@@ -118,40 +118,33 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
end
end
- %w[
- experiment
- experiment_enabled?
- push_frontend_experiment
- Gitlab::Experimentation.active?
- ].each do |feature_flag_method|
- context "#{feature_flag_method} method" do
- context 'a string feature flag' do
- include_examples 'sets flag as used', %Q|#{feature_flag_method}("baz")|, %w[baz baz_experiment_percentage]
- end
+ context 'with the experiment method' do
+ context 'a string feature flag' do
+ include_examples 'sets flag as used', %q|experiment("baz")|, %w[baz]
+ end
- context 'a symbol feature flag' do
- include_examples 'sets flag as used', %Q|#{feature_flag_method}(:baz)|, %w[baz baz_experiment_percentage]
- end
+ context 'a symbol feature flag' do
+ include_examples 'sets flag as used', %q|experiment(:baz)|, %w[baz]
+ end
- context 'an interpolated string feature flag with a string prefix' do
- include_examples 'sets flag as used', %Q|#{feature_flag_method}("foo_\#{bar}")|, %w[foo_hello foo_world]
- end
+ context 'an interpolated string feature flag with a string prefix' do
+ include_examples 'sets flag as used', %Q|experiment("foo_\#{bar}")|, %w[foo_hello foo_world]
+ end
- context 'an interpolated symbol feature flag with a string prefix' do
- include_examples 'sets flag as used', %Q|#{feature_flag_method}(:"foo_\#{bar}")|, %w[foo_hello foo_world]
- end
+ context 'an interpolated symbol feature flag with a string prefix' do
+ include_examples 'sets flag as used', %Q|experiment(:"foo_\#{bar}")|, %w[foo_hello foo_world]
+ end
- context 'an interpolated string feature flag with a string prefix and suffix' do
- include_examples 'does not set any flags as used', %Q|#{feature_flag_method}(:"foo_\#{bar}_baz")|
- end
+ context 'an interpolated string feature flag with a string prefix and suffix' do
+ include_examples 'does not set any flags as used', %Q|experiment(:"foo_\#{bar}_baz")|
+ end
- context 'a dynamic string feature flag as a variable' do
- include_examples 'does not set any flags as used', %Q|#{feature_flag_method}(a_variable, an_arg)|
- end
+ context 'a dynamic string feature flag as a variable' do
+ include_examples 'does not set any flags as used', %q|experiment(a_variable, an_arg)|
+ end
- context 'an integer feature flag' do
- include_examples 'does not set any flags as used', %Q|#{feature_flag_method}(123)|
- end
+ context 'an integer feature flag' do
+ include_examples 'does not set any flags as used', %q|experiment(123)|
end
end
diff --git a/spec/rubocop/cop/gitlab/no_code_coverage_comment_spec.rb b/spec/rubocop/cop/gitlab/no_code_coverage_comment_spec.rb
new file mode 100644
index 00000000000..f0c0297d266
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/no_code_coverage_comment_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require_relative '../../../../rubocop/cop/gitlab/no_code_coverage_comment'
+
+RSpec.describe RuboCop::Cop::Gitlab::NoCodeCoverageComment do
+ let(:msg) { format(described_class::MSG, nocov_comment: nocov_comment) }
+ let(:nocov_comment) { ":#{comment_token}:" }
+
+ shared_examples 'nocov check' do
+ it 'flags related code comments' do
+ expect_offense(<<~RUBY, nocov_token: comment_token, msg: msg)
+ # :%{nocov_token}:
+ ^^^{nocov_token} %{msg}
+ def method
+ end
+ #:%{nocov_token}:
+ ^^^{nocov_token} %{msg}
+
+ def other_method
+ if expr
+ # :%{nocov_token}: With some additional comments
+ ^^^{nocov_token} %{msg}
+ value << line.strip
+ # :%{nocov_token}:
+ ^^^{nocov_token} %{msg}
+ end
+ end
+ RUBY
+ end
+
+ it 'ignores unrelated comments' do
+ expect_no_offenses(<<~RUBY)
+ # Other comments are ignored :#{comment_token}:
+ #
+ # # :#{comment_token}:
+ RUBY
+ end
+ end
+
+ context 'with nocov as default comment token' do
+ it_behaves_like 'nocov check' do
+ let(:comment_token) { described_class::DEFAULT_COMMENT_TOKEN }
+ end
+ end
+
+ context 'with configured comment token' do
+ it_behaves_like 'nocov check' do
+ let(:comment_token) { 'skipit' }
+
+ let(:config) do
+ RuboCop::Config.new(
+ 'Gitlab/NoCodeCoverageComment' => {
+ 'CommentToken' => comment_token
+ }
+ )
+ end
+ end
+ end
+end
diff --git a/spec/rubocop/cop/gitlab/service_response_spec.rb b/spec/rubocop/cop/gitlab/service_response_spec.rb
new file mode 100644
index 00000000000..84cf0dbff52
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/service_response_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require_relative '../../../../rubocop/cop/gitlab/service_response'
+
+RSpec.describe RuboCop::Cop::Gitlab::ServiceResponse do
+ subject(:cop) { described_class.new }
+
+ it 'does not flag the `http_status:` param on a homonym method' do
+ expect_no_offenses("MyClass.error(http_status: :ok)")
+ end
+
+ it 'does not flag calls without params' do
+ expect_no_offenses('ServiceResponse.error')
+ end
+
+ it 'does not flag the offense when `http_status` is not used' do
+ expect_no_offenses('ServiceResponse.error(message: "some error", reason: :bad_time)')
+ end
+
+ it 'flags the use of `http_status:` parameter in ServiceResponse in error' do
+ expect_offense(<<~CODE, msg: described_class::MSG)
+ ServiceResponse.error(message: "some error", http_status: :bad_request)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
+ CODE
+ end
+
+ it 'flags the use of `http_status:` parameter in ServiceResponse in success' do
+ expect_offense(<<~CODE, msg: described_class::MSG)
+ ServiceResponse.success(message: "some error", http_status: :bad_request)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
+ CODE
+ end
+
+ it 'flags the use of `http_status:` parameter in ServiceResponse in initializer' do
+ expect_offense(<<~CODE, msg: described_class::MSG)
+ ServiceResponse.new(message: "some error", http_status: :bad_request)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
+ CODE
+ end
+end