diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/rubocop/cop/redis_queue_usage_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/redis_queue_usage_spec.rb')
-rw-r--r-- | spec/rubocop/cop/redis_queue_usage_spec.rb | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/spec/rubocop/cop/redis_queue_usage_spec.rb b/spec/rubocop/cop/redis_queue_usage_spec.rb new file mode 100644 index 00000000000..9861a6a79d9 --- /dev/null +++ b/spec/rubocop/cop/redis_queue_usage_spec.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' + +require_relative '../../../rubocop/cop/redis_queue_usage' + +RSpec.describe RuboCop::Cop::RedisQueueUsage do + let(:msg) { described_class::MSG } + + context 'when assigning Gitlab::Redis::Queues as a variable' do + it 'registers offence for any variable assignment' do + expect_offense(<<~PATTERN) + x = Gitlab::Redis::Queues + ^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignment' do + expect_offense(<<~PATTERN) + X = Gitlab::Redis::Queues + ^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + end + + context 'when assigning Gitlab::Redis::Queues as a part of an array' do + it 'registers offence for variable assignments' do + expect_offense(<<~PATTERN) + x = [ Gitlab::Redis::Cache, Gitlab::Redis::Queues, Gitlab::Redis::SharedState ] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments' do + expect_offense(<<~PATTERN) + ALL = [ Gitlab::Redis::Cache, Gitlab::Redis::Queues, Gitlab::Redis::SharedState ] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments while invoking function' do + expect_offense(<<~PATTERN) + ALL = [ Gitlab::Redis::Cache, Gitlab::Redis::Queues, Gitlab::Redis::SharedState ].freeze + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments while invoking multiple functions' do + expect_offense(<<~PATTERN) + ALL = [ Gitlab::Redis::Cache, Gitlab::Redis::Queues, Gitlab::Redis::SharedState ].foo.freeze + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + end + + context 'when assigning Gitlab::Redis::Queues as a part of a hash' do + it 'registers offence for variable assignments' do + expect_offense(<<~PATTERN) + x = { "test": Gitlab::Redis::Queues, "test2": Gitlab::Redis::SharedState } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments' do + expect_offense(<<~PATTERN) + ALL = { "test": Gitlab::Redis::Queues, "test2": Gitlab::Redis::SharedState } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments while invoking function' do + expect_offense(<<~PATTERN) + ALL = { "test": Gitlab::Redis::Queues, "test2": Gitlab::Redis::SharedState }.freeze + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for constant assignments while invoking multiple functions' do + expect_offense(<<~PATTERN) + ALL = { "test": Gitlab::Redis::Queues, "test2": Gitlab::Redis::SharedState }.foo.freeze + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + end + + it 'registers offence for any invocation of Gitlab::Redis::Queues methods' do + expect_offense(<<~PATTERN) + Gitlab::Redis::Queues.params + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence for using Gitlab::Redis::Queues as parameter in method calls' do + expect_offense(<<~PATTERN) + use_redis(Gitlab::Redis::Queues) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end +end |