diff options
Diffstat (limited to 'spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb')
-rw-r--r-- | spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb index 1d09c720bf7..08634d5753a 100644 --- a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb +++ b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb @@ -2,42 +2,33 @@ require 'fast_spec_helper' require 'rubocop' -require 'rubocop/rspec/support' require_relative '../../../../rubocop/cop/gitlab/module_with_instance_variables' RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do - include CopHelper + let(:msg) { "Do not use instance variables in a module. [...]" } subject(:cop) { described_class.new } - shared_examples('registering offense') do |options| - let(:offending_lines) { options[:offending_lines] } - + shared_examples('registering offense') do it 'registers an offense when instance variable is used in a module' do - inspect_source(source) - - aggregate_failures do - expect(cop.offenses.size).to eq(offending_lines.size) - expect(cop.offenses.map(&:line)).to eq(offending_lines) - end + expect_offense(source) end end shared_examples('not registering offense') do it 'does not register offenses' do - inspect_source(source) - - expect(cop.offenses).to be_empty + expect_no_offenses(source) end end context 'when source is a regular module' do - it_behaves_like 'registering offense', offending_lines: [3] do + it_behaves_like 'registering offense' do let(:source) do <<~RUBY module M def f @f = true + ^^^^^^^^^ #{msg} end end RUBY @@ -46,13 +37,14 @@ RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do end context 'when source is a nested module' do - it_behaves_like 'registering offense', offending_lines: [4] do + it_behaves_like 'registering offense' do let(:source) do <<~RUBY module N module M def f @f = true + ^^^^^^^^^ #{msg} end end end @@ -62,13 +54,14 @@ RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do end context 'when source is a nested module with multiple offenses' do - it_behaves_like 'registering offense', offending_lines: [4, 12] do + it_behaves_like 'registering offense' do let(:source) do <<~RUBY module N module M def f @f = true + ^^^^^^^^^ #{msg} end def g @@ -77,6 +70,7 @@ RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do def h @h = true + ^^^^^^^^^ #{msg} end end end @@ -129,12 +123,13 @@ RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do end context 'when source is using simple or ivar assignment with other ivar' do - it_behaves_like 'registering offense', offending_lines: [3] do + it_behaves_like 'registering offense' do let(:source) do <<~RUBY module M def f @f ||= g(@g) + ^^ #{msg} end end RUBY @@ -143,13 +138,15 @@ RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do end context 'when source is using or ivar assignment with something else' do - it_behaves_like 'registering offense', offending_lines: [3, 4] do + it_behaves_like 'registering offense' do let(:source) do <<~RUBY module M def f @f ||= true + ^^ #{msg} @f.to_s + ^^ #{msg} end end RUBY |