Skip to content

Commit

Permalink
Merge pull request #9598 from kachick/fix-shareable_constant_value
Browse files Browse the repository at this point in the history
Fix RuboCop::MagicComment#valid_shareable_constant_value?
  • Loading branch information
koic committed Mar 13, 2021
2 parents 972656f + a5ffce7 commit 347eba0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_fix_valid_shareable_constant_value.md
@@ -0,0 +1 @@
* [#9598](https://github.com/rubocop/rubocop/pull/9598): Fix RuboCop::MagicComment#valid_shareable_constant_value?. ([@kachick][])
2 changes: 1 addition & 1 deletion lib/rubocop/magic_comment.rb
Expand Up @@ -47,7 +47,7 @@ def valid_literal_value?
end

def valid_shareable_constant_value?
%w[none literal experimental_everything experimental_copy].include?(shareable_constant_values)
%w[none literal experimental_everything experimental_copy].include?(shareable_constant_value)
end

# Was a magic comment for the frozen string literal found?
Expand Down
40 changes: 40 additions & 0 deletions spec/rubocop/magic_comment_spec.rb
Expand Up @@ -151,4 +151,44 @@
include_examples 'magic comment',
'# vim:fileencoding=utf-8',
encoding: nil

describe '#valid_shareable_constant_value?' do
subject { described_class.parse(comment).valid_shareable_constant_value? }

context 'when given comment specified as `none`' do
let(:comment) { '# shareable_constant_value: none' }

it { is_expected.to eq(true) }
end

context 'when given comment specified as `literal`' do
let(:comment) { '# shareable_constant_value: literal' }

it { is_expected.to eq(true) }
end

context 'when given comment specified as `experimental_everything`' do
let(:comment) { '# shareable_constant_value: experimental_everything' }

it { is_expected.to eq(true) }
end

context 'when given comment specified as `experimental_copy`' do
let(:comment) { '# shareable_constant_value: experimental_copy' }

it { is_expected.to eq(true) }
end

context 'when given comment specified as unknown value' do
let(:comment) { '# shareable_constant_value: unknown' }

it { is_expected.to eq(false) }
end

context 'when given comment is not specified' do
let(:comment) { '' }

it { is_expected.to eq(false) }
end
end
end

0 comments on commit 347eba0

Please sign in to comment.