Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb')
-rw-r--r--spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb47
1 files changed, 22 insertions, 25 deletions
diff --git a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
index bed06ab2b17..19e5fe946be 100644
--- a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
+++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
@@ -2,78 +2,75 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/gitlab/const_get_inherit_false'
RSpec.describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'Object.const_get' do
- it 'registers an offense with no 2nd argument' do
+ it 'registers an offense with no 2nd argument and corrects' do
expect_offense(<<~PATTERN)
Object.const_get(:CONSTANT)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
- end
- it 'autocorrects' do
- expect(autocorrect_source('Object.const_get(:CONSTANT)')).to eq('Object.const_get(:CONSTANT, false)')
+ expect_correction(<<~PATTERN)
+ Object.const_get(:CONSTANT, false)
+ PATTERN
end
context 'inherit=false' do
it 'does not register an offense' do
expect_no_offenses(<<~PATTERN)
- Object.const_get(:CONSTANT, false)
+ Object.const_get(:CONSTANT, false)
PATTERN
end
end
context 'inherit=true' do
- it 'registers an offense' do
+ it 'registers an offense and corrects' do
expect_offense(<<~PATTERN)
- Object.const_get(:CONSTANT, true)
- ^^^^^^^^^ Use inherit=false when using const_get.
+ Object.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
- end
- it 'autocorrects' do
- expect(autocorrect_source('Object.const_get(:CONSTANT, true)')).to eq('Object.const_get(:CONSTANT, false)')
+ expect_correction(<<~PATTERN)
+ Object.const_get(:CONSTANT, false)
+ PATTERN
end
end
end
context 'const_get for a nested class' do
- it 'registers an offense on reload usage' do
+ it 'registers an offense on reload usage and corrects' do
expect_offense(<<~PATTERN)
Nested::Blog.const_get(:CONSTANT)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
- end
- it 'autocorrects' do
- expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ expect_correction(<<~PATTERN)
+ Nested::Blog.const_get(:CONSTANT, false)
+ PATTERN
end
context 'inherit=false' do
it 'does not register an offense' do
expect_no_offenses(<<~PATTERN)
- Nested::Blog.const_get(:CONSTANT, false)
+ Nested::Blog.const_get(:CONSTANT, false)
PATTERN
end
end
context 'inherit=true' do
- it 'registers an offense if inherit is true' do
+ it 'registers an offense if inherit is true and corrects' do
expect_offense(<<~PATTERN)
- Nested::Blog.const_get(:CONSTANT, true)
- ^^^^^^^^^ Use inherit=false when using const_get.
+ Nested::Blog.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
- end
- it 'autocorrects' do
- expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT, true)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ expect_correction(<<~PATTERN)
+ Nested::Blog.const_get(:CONSTANT, false)
+ PATTERN
end
end
end