Sha256: cc118c3c364db02be22da4e20df4a041d657dce6ab776f938084dab5014e2f3f

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8

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

  it 'finds `allow_any_instance_of` instead of an instance double' do
    inspect_source(cop, ['before do',
                         '  allow_any_instance_of(Object).to receive(:foo)',
                         'end'])
    expect(cop.messages)
      .to eq(['Avoid stubbing using `allow_any_instance_of`'])
    expect(cop.highlights).to eq(['allow_any_instance_of(Object)'])
    expect(cop.offenses.map(&:line).sort).to eq([2])
  end

  it 'finds `expect_any_instance_of` instead of an instance double' do
    inspect_source(cop, ['before do',
                         '  expect_any_instance_of(Object).to receive(:foo)',
                         'end'])
    expect(cop.messages)
      .to eq(['Avoid stubbing using `expect_any_instance_of`'])
    expect(cop.highlights).to eq(['expect_any_instance_of(Object)'])
    expect(cop.offenses.map(&:line).sort).to eq([2])
  end

  it 'finds old `any_instance` syntax instead of an instance double' do
    inspect_source(cop, ['before do',
                         '  Object.any_instance.should_receive(:foo)',
                         'end'])
    expect(cop.messages)
      .to eq(['Avoid stubbing using `any_instance`'])
    expect(cop.highlights).to eq(['Object.any_instance'])
    expect(cop.offenses.map(&:line).sort).to eq([2])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.4.1 spec/rubocop/cop/rspec/any_instance_spec.rb
rubocop-rspec-1.4.0 spec/rubocop/cop/rspec/any_instance_spec.rb