spec/rubocop/cop/rspec/instance_variable_spec.rb in rubocop-rspec-1.6.0 vs spec/rubocop/cop/rspec/instance_variable_spec.rb in rubocop-rspec-1.7.0

- old
+ new

@@ -33,6 +33,43 @@ expect_no_violations(<<-RUBY) @foo = [] @foo.empty? RUBY end + + # Regression test for nevir/rubocop-rspec#115 + it 'ignores instance variables outside of specs' do + expect_no_violations(<<-RUBY, filename: 'lib/source_code.rb') + feature do + @foo = bar + + @foo + end + RUBY + end + + context 'when configured with AssignmentOnly', :config do + subject(:cop) { described_class.new(config) } + + let(:cop_config) do + { 'AssignmentOnly' => true } + end + + it 'flags an instance variable when it is also assigned' do + expect_violation(<<-RUBY) + describe MyClass do + before { @foo = [] } + it { expect(@foo).to be_empty } + ^^^^ Use `let` instead of an instance variable + end + RUBY + end + + it 'ignores an instance variable when it is not assigned' do + expect_no_violations(<<-RUBY) + describe MyClass do + it { expect(@foo).to be_empty } + end + RUBY + end + end end