Sha256: 54fa9fcf20d9fa8d4f649ff8079af088afd2313d4fc1903c080481c91a3e8672

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offense for while with exclamation point condition' do
    inspect_source(cop,
                   ['while !a_condition',
                    '  some_method',
                    'end',
                    'some_method while !a_condition'
                   ])
    expect(cop.messages).to eq(
      ['Favor until over while for negative conditions.'] * 2)
  end

  it 'registers an offense for while with "not" condition' do
    inspect_source(cop,
                   ['while (not a_condition)',
                    '  some_method',
                    'end',
                    'some_method while not a_condition'])
    expect(cop.messages).to eq(
      ['Favor until over while for negative conditions.'] * 2)
    expect(cop.offenses.map(&:line)).to eq([1, 4])
  end

  it 'accepts an while where only part of the contition is negated' do
    inspect_source(cop,
                   ['while !a_condition && another_condition',
                    '  some_method',
                    'end',
                    'while not a_condition or another_condition',
                    '  some_method',
                    'end',
                    'some_method while not a_condition or other_cond'])
    expect(cop.messages).to be_empty
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb