Sha256: aa4fc49345d7a8c7b8843bab1d845b36787c80852f9c89a3f2013d5665ca1536

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::RSpec::InstanceVariable do
  subject(:cop) { described_class.new }

  it 'finds an instance variable inside a describe' do
    inspect_source(cop, ['describe MyClass do',
                         '  before { @foo = [] }',
                         '  it { expect(@foo).to be_emtpy }',
                         'end'])
    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 'finds an instance variable inside a shared example' do
    inspect_source(cop, ["shared_examples 'shared example' do",
                         '  it { expect(@foo).to be_emtpy }',
                         'end'])
    expect(cop.offenses.size).to eq(1)
    expect(cop.offenses.map(&:line).sort).to eq([2])
    expect(cop.messages).to eq(['Use `let` instead of an instance variable'])
  end

  it 'ignores an instance variable without describe' do
    inspect_source(cop, ['@foo = []',
                         '@foo.empty?'])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-rspec-1.2.0 spec/rubocop/cop/rspec/instance_variable_spec.rb
rubocop-rspec-1.1.0 spec/rubocop/cop/rspec/instance_variable_spec.rb
rubocop-rspec-1.0.1 spec/rubocop/cop/rspec/instance_variable_spec.rb
rubocop-rspec-1.0 spec/rubocop/cop/rspec/instance_variable_spec.rb
rubocop-rspec-1.0.rc3 spec/rubocop/cop/rspec/instance_variable_spec.rb