Sha256: 953f6c32969b4b2c4367cf16f16c4261780fd859ca842dce3255f42e368ec197

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offence for x % 2 == 0' do
    inspect_source(cop,
                   ['x % 2 == 0'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.even?'])
  end

  it 'registers an offence for x % 2 != 0' do
    inspect_source(cop,
                   ['x % 2 != 0'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.odd?'])
  end

  it 'registers an offence for (x % 2) == 0' do
    inspect_source(cop,
                   ['(x % 2) == 0'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.even?'])
  end

  it 'registers an offence for (x % 2) != 0' do
    inspect_source(cop,
                   ['(x % 2) != 0'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.odd?'])
  end

  it 'registers an offence for x % 2 == 1' do
    inspect_source(cop,
                   ['x % 2 == 1'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.odd?'])
  end

  it 'registers an offence for x % 2 != 1' do
    inspect_source(cop,
                   ['x % 2 != 1'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.even?'])
  end

  it 'registers an offence for (x % 2) == 1' do
    inspect_source(cop,
                   ['(x % 2) == 1'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.odd?'])
  end

  it 'registers an offence for (x % 2) != 1' do
    inspect_source(cop,
                   ['(x % 2) != 1'])
    expect(cop.offences.size).to eq(1)
    expect(cop.messages).to eq(['Use Fixnum.even?'])
  end

  it 'accepts x % 3 == 0' do
    inspect_source(cop,
                   ['x % 3 == 0'])
    expect(cop.offences).to be_empty
  end

  it 'accepts x % 3 != 0' do
    inspect_source(cop,
                   ['x % 3 != 0'])
    expect(cop.offences).to be_empty
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.16.0 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/even_odd_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/even_odd_spec.rb