Skip to content

Commit

Permalink
[Fix rubocop#9328] Removing nil check, refactoring spec
Browse files Browse the repository at this point in the history
  • Loading branch information
thearjunmdas committed Jul 14, 2021
1 parent aed2f41 commit 1fb68ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion lib/rubocop/cop/style/mutable_constant.rb
Expand Up @@ -133,7 +133,6 @@ def frozen_string_literal?(node)

def shareable_constant_value?(node)
return false if target_ruby_version < 3.0
return false if node.nil?

recent_shareable_value? node
end
Expand Down
22 changes: 10 additions & 12 deletions spec/rubocop/cop/style/mutable_constant_spec.rb
Expand Up @@ -43,11 +43,10 @@
end
end

shared_examples 'freezing all constants' do |o|
shared_examples 'literals that are frozen' do |o|
let(:prefix) { o }

it_behaves_like 'immutable objects', '[1, 2, 3]'
it_behaves_like 'immutable objects', 'Set[1, 2]'
it_behaves_like 'immutable objects', '%w(a b c)'
it_behaves_like 'immutable objects', '{ a: 1, b: 2 }'
it_behaves_like 'immutable objects', "'str'"
Expand All @@ -62,11 +61,10 @@
it_behaves_like 'immutable objects', "::ENV['foo']"
end

shared_examples 'not freezing all constants' do |o|
shared_examples 'literals that are not frozen' do |o|
let(:prefix) { o }

it_behaves_like 'mutable objects', '[1, 2, 3]'
it_behaves_like 'immutable objects', 'Set[1, 2]'
it_behaves_like 'mutable objects', '%w(a b c)'
it_behaves_like 'mutable objects', '{ a: 1, b: 2 }'
it_behaves_like 'mutable objects', "'str'"
Expand Down Expand Up @@ -198,10 +196,10 @@
end

context 'when using shareable_constant_value' do
it_behaves_like 'freezing all constants', '# shareable_constant_value: literal'
it_behaves_like 'freezing all constants', '# shareable_constant_value: experimental_everything'
it_behaves_like 'freezing all constants', '# shareable_constant_value: experimental_copy'
it_behaves_like 'not freezing all constants', '# shareable_constant_value: none'
it_behaves_like 'literals that are frozen', '# shareable_constant_value: literal'
it_behaves_like 'literals that are frozen', '# shareable_constant_value: experimental_everything'
it_behaves_like 'literals that are frozen', '# shareable_constant_value: experimental_copy'
it_behaves_like 'literals that are not frozen', '# shareable_constant_value: none'
end

it 'raises offense when shareable_constant_value is specified as an inline comment' do
Expand Down Expand Up @@ -287,10 +285,10 @@
end

context 'when using shareable_constant_values' do
it_behaves_like 'not freezing all constants', '# shareable_constant_value: literal'
it_behaves_like 'not freezing all constants', '# shareable_constant_value: experimental_everything'
it_behaves_like 'not freezing all constants', '# shareable_constant_value: experimental_copy'
it_behaves_like 'not freezing all constants', '# shareable_constant_value: none'
it_behaves_like 'literals that are not frozen', '# shareable_constant_value: literal'
it_behaves_like 'literals that are not frozen', '# shareable_constant_value: experimental_everything'
it_behaves_like 'literals that are not frozen', '# shareable_constant_value: experimental_copy'
it_behaves_like 'literals that are not frozen', '# shareable_constant_value: none'
end
end

Expand Down

0 comments on commit 1fb68ff

Please sign in to comment.