Sha256: 345796656ea393521afdaf7d7e93d5f4ce5336ad06d21c8ddc642b6624be16cb

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe FavorUntilOverNegatedWhile do
        let(:fav_until) { FavorUntilOverNegatedWhile.new }

        it 'registers an offence for while with exclamation point condition' do
          inspect_source(fav_until,
                         ['while !a_condition',
                          '  some_method',
                          'end',
                          'some_method while !a_condition',
                         ])
          expect(fav_until.offences.map(&:message)).to eq(
            ['Favor until over while for negative conditions.'] * 2)
        end

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

        it 'accepts an while where only part of the contition is negated' do
          inspect_source(fav_until,
                         ['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(fav_until.offences.map(&:message)).to be_empty
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubocop-0.12.0 spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb
rubocop-0.11.1 spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb
rubocop-0.11.0 spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb
rubocop-0.10.0 spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb
rubocop-0.9.1 spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb
sabat-rubocop-0.9.0 spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb
rubocop-0.9.0 spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb