Sha256: be7fc387383784e4cfff49f34adbdef9021e279fcef168996fa8dbb862f3d52f

Contents?: true

Size: 950 Bytes

Versions: 4

Compression:

Stored size: 950 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Lint::UselessElseWithoutRescue do
  subject(:cop) { described_class.new }

  before do
    inspect_source(cop, source)
  end

  context 'with `else` without `rescue`' do
    let(:source) do
      [
        'begin',
        '  do_something',
        'else',
        '  handle_unknown_errors',
        'end'
      ]
    end

    it 'registers an offence' do
      expect(cop.offences.size).to eq(1)
      expect(cop.offences.first.message)
        .to eq('Else without rescue is useless')
      expect(cop.highlights).to eq(['else'])
    end
  end

  context 'with `else` with `rescue`' do
    let(:source) do
      [
        'begin',
        '  do_something',
        'rescue ArgumentError',
        '  handle_argument_error',
        'else',
        '  handle_unknown_errors',
        'end'
      ]
    end

    it 'accepts' do
      expect(cop.offences).to be_empty
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.18.1 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.18.0 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.17.0 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb