diff options
Diffstat (limited to 'spec/rubocop/cop')
3 files changed, 112 insertions, 5 deletions
diff --git a/spec/rubocop/cop/background_migration/feature_category_spec.rb b/spec/rubocop/cop/background_migration/feature_category_spec.rb new file mode 100644 index 00000000000..359520b1d9f --- /dev/null +++ b/spec/rubocop/cop/background_migration/feature_category_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' +require_relative '../../../../rubocop/cop/background_migration/feature_category' + +RSpec.describe RuboCop::Cop::BackgroundMigration::FeatureCategory, feature_category: :database do + let(:cop) { described_class.new } + + context 'for non background migrations' do + before do + allow(cop).to receive(:in_background_migration?).and_return(false) + end + + it 'does not throw any offense' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < Gitlab::BackgroundMigration::BatchedMigrationJob + def perform; end + end + end + end + RUBY + end + end + + context 'for background migrations' do + before do + allow(cop).to receive(:in_background_migration?).and_return(true) + end + + it 'throws offense on not defining the feature_category' do + expect_offense(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob1 < Gitlab::BackgroundMigration::BatchedMigrationJob + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} + end + end + end + RUBY + end + + it 'throws offense on not defining a valid feature_category' do + expect_offense(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob1 < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :invalid_random + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::INVALID_FEATURE_CATEGORY_MSG} + end + end + end + RUBY + end + + it 'will not throw offense on defining a valid feature_category' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < Gitlab::BackgroundMigration::BatchedMigrationJob + feature_category :database + + def perform; end + end + end + end + RUBY + end + end +end diff --git a/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb b/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb index 0ed699f4e8c..fde53f8f98c 100644 --- a/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb +++ b/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb @@ -11,7 +11,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do class Foo def memoized_method strong_memoize(:memoized_method) do - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. 'This is a memoized method' end end @@ -35,7 +35,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do class Foo def enabled? strong_memoize(:enabled) do - ^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. true end end @@ -47,7 +47,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do def enabled? true end - strong_memoize_attr :enabled?, :enabled + strong_memoize_attr :enabled? end RUBY end @@ -62,7 +62,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do msg = 'This is a memoized method' strong_memoize(:memoized_method) do - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. msg end end @@ -72,4 +72,32 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do expect_no_corrections end end + + context 'when strong_memoize() is used in a method with parameters' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + class Foo + def memoized_method(param) + strong_memoize(:memoized_method) do + param.to_s + end + end + end + RUBY + end + end + + context 'when strong_memoize() is used in a singleton method' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + class Foo + def self.memoized_method + strong_memoize(:memoized_method) do + 'this is a memoized method' + end + end + end + RUBY + end + end end diff --git a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb index b0551a79c50..53f19cd01ee 100644 --- a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb +++ b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb @@ -3,7 +3,7 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/lint/last_keyword_argument' -RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do +RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, :ruby27, feature_category: :not_owned do before do described_class.instance_variable_set(:@keyword_warnings, nil) allow(Dir).to receive(:glob).and_call_original @@ -156,5 +156,13 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do users.call(params) SOURCE end + + context 'with Ruby 3.0', :ruby30 do + it 'does not register an offense with known warning' do + expect_no_offenses(<<~SOURCE, 'create_service.rb') + users.call(params) + SOURCE + end + end end end |