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:
authorLin Jen-Shin <godfat@godfat.org>2017-09-18 20:25:23 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-09-18 20:29:32 +0300
commit6a4ee9aa7140862075cafae1ddebd133eec52b5b (patch)
tree9890bb5c906a0d6e207149ae5fe1df84d213fa7c /spec/rubocop
parent9ae92b8caa6c11d8860f86b7d6378062215d1b72 (diff)
Allow simple ivar ||= form. Update accordingly
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/module_with_instance_variables_spec.rb89
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