Sha256: 0399eefb2b3e98f03cfa89849761ad4dfb542c6ae073a06e1e26196213369ad7

Contents?: true

Size: 876 Bytes

Versions: 13

Compression:

Stored size: 876 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe UnlessElse do
      let(:ue) { UnlessElse.new }

      it 'registers an offence for an unless with else' do
        inspect_source(ue, 'file.rb', ['unless x',
                                       '  a = 1',
                                       'else',
                                       '  a = 0',
                                       'end'])
        expect(ue.offences.map(&:message)).to eq(
          ['Never use unless with else. Rewrite these with the ' +
           'positive case first.'])
      end

      it 'accepts an unless without else' do
        inspect_source(ue, 'file.rb', ['unless x',
                                       '  a = 1',
                                       'end'])
        expect(ue.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/unless_else_spec.rb
rubocop-0.7.1 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.7.0 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.6.1 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.6.0 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.5.0 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.6 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.5 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.4 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.3 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.2 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.1 spec/rubocop/cops/unless_else_spec.rb
rubocop-0.4.0 spec/rubocop/cops/unless_else_spec.rb