diff options
Diffstat (limited to 'spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb')
-rw-r--r-- | spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb | 36 |
1 files changed, 32 insertions, 4 deletions
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 |