diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-09-19 01:25:23 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-09-19 01:29:32 +0800 |
commit | 6a4ee9aa7140862075cafae1ddebd133eec52b5b (patch) | |
tree | 9890bb5c906a0d6e207149ae5fe1df84d213fa7c /spec/rubocop | |
parent | 9ae92b8caa6c11d8860f86b7d6378062215d1b72 (diff) | |
download | gitlab-ce-6a4ee9aa7140862075cafae1ddebd133eec52b5b.tar.gz |
Allow simple ivar ||= form. Update accordingly
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/module_with_instance_variables_spec.rb | 89 |
1 files changed, 72 insertions, 17 deletions
diff --git a/spec/rubocop/cop/module_with_instance_variables_spec.rb b/spec/rubocop/cop/module_with_instance_variables_spec.rb index ce2e156e423..bac39117dba 100644 --- a/spec/rubocop/cop/module_with_instance_variables_spec.rb +++ b/spec/rubocop/cop/module_with_instance_variables_spec.rb @@ -19,12 +19,20 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do end end + shared_examples('not registering offense') do + it 'does not register offenses' do + inspect_source(cop, source) + + expect(cop.offenses).to be_empty + end + end + context 'when source is a regular module' do let(:source) do <<~RUBY module M def f - @f ||= true + @f = true end end RUBY @@ -59,7 +67,7 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do module N module M def f - @f ||= true + @f = true end def g @@ -79,39 +87,86 @@ describe RuboCop::Cop::ModuleWithInstanceVariables do it_behaves_like 'registering offense' end - context 'when source is offending but it is a rails helper' do - before do - allow(cop).to receive(:rails_helper?).and_return(true) + context 'with regular ivar assignment' do + let(:source) do + <<~RUBY + module M + def f + @f = true + end + end + RUBY + end + + context 'when source is offending but it is a rails helper' do + before do + allow(cop).to receive(:rails_helper?).and_return(true) + end + + it_behaves_like 'not registering offense' end - it 'does not register offenses' do - inspect_source(cop, <<~RUBY) + context 'when source is offending but it is a rails mailer' do + before do + allow(cop).to receive(:rails_mailer?).and_return(true) + end + + it_behaves_like 'not registering offense' + end + + context 'when source is offending but it is a spec helper' do + before do + allow(cop).to receive(:spec_helper?).and_return(true) + end + + it_behaves_like 'not registering offense' + end + end + + context 'when source is using simple or ivar assignment' do + let(:source) do + <<~RUBY module M def f @f ||= true end end RUBY - - expect(cop.offenses).to be_empty end + + it_behaves_like 'not registering offense' end - context 'when source is offending but it is a rails mailer' do - before do - allow(cop).to receive(:rails_mailer?).and_return(true) + context 'when source is using simple or ivar assignment with other ivar' do + let(:source) do + <<~RUBY + module M + def f + @f ||= g(@g) + end + end + RUBY end - it 'does not register offenses' do - inspect_source(cop, <<~RUBY) + let(:offending_lines) { [3] } + + it_behaves_like 'registering offense' + end + + context 'when source is using or ivar assignment with something else' do + let(:source) do + <<~RUBY module M def f - @f = true + @f ||= true + @f.to_s end end RUBY - - expect(cop.offenses).to be_empty end + + let(:offending_lines) { [3, 4] } + + it_behaves_like 'registering offense' end end |