Sha256: 6a4b6e3cb91fbd0c9c0b4b043ac029daead2742291a6b9a369838468fc069ac8

Contents?: true

Size: 616 Bytes

Versions: 1

Compression:

Stored size: 616 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::NilComparison do
  subject(:cop) { described_class.new }

  it 'registers an offense for == nil' do
    inspect_source(cop, 'x == nil')
    expect(cop.offenses.size).to eq(1)
    expect(cop.highlights).to eq(['=='])
  end

  it 'registers an offense for === nil' do
    inspect_source(cop, 'x === nil')
    expect(cop.offenses.size).to eq(1)
    expect(cop.highlights).to eq(['==='])
  end

  it 'autocorrects by replacing == nil with .nil?' do
    corrected = autocorrect_source(cop, 'x == nil')
    expect(corrected).to eq 'x.nil?'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.20.0 spec/rubocop/cop/style/nil_comparison_spec.rb