spec/rubocop/cop/rspec/instance_variable_spec.rb in rubocop-rspec-1.5.1 vs spec/rubocop/cop/rspec/instance_variable_spec.rb in rubocop-rspec-1.5.2
- old
+ new
@@ -1,7 +1,5 @@
-# encoding: utf-8
-
describe RuboCop::Cop::RSpec::InstanceVariable do
subject(:cop) { described_class.new }
it 'finds an instance variable inside a describe' do
inspect_source(
@@ -14,9 +12,22 @@
]
)
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line).sort).to eq([3])
expect(cop.messages).to eq(['Use `let` instead of an instance variable'])
+ end
+
+ it 'ignores non-spec blocks' do
+ inspect_source(
+ cop,
+ [
+ 'not_rspec do',
+ ' before { @foo = [] }',
+ ' it { expect(@foo).to be_empty }',
+ 'end'
+ ]
+ )
+ expect(cop.offenses).to be_empty
end
it 'finds an instance variable inside a shared example' do
inspect_source(
cop,