Sha256: bfbf0388fa5a83055b2e05d1b506f266dbedd55c99ba1d127bdac9fff0d0631f

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

      it 'registers an offence for while with exclamation point condition' do
        inspect_source(fav_until, 'file.rb',
                       ['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, 'file.rb',
                       ['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_number)).to eq([1, 4])
      end

      it 'accepts an while where only part of the contition is negated' do
        inspect_source(fav_until, 'file.rb',
                       ['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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubocop-0.7.2 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.7.1 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.7.0 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.6.1 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.6.0 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.5.0 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.6 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.5 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.4 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.3 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.2 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.1 spec/rubocop/cops/favor_until_over_negated_while_spec.rb
rubocop-0.4.0 spec/rubocop/cops/favor_until_over_negated_while_spec.rb