Sha256: f9e4301d4c9d1e8c8c526030b3500f02b1aaca47de1ed877b5daceb0a4d8a113

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 offense' do
      expect(cop.offenses.size).to eq(1)
      expect(cop.offenses.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.offenses).to be_empty
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.20.1 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.20.0 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.19.1 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb
rubocop-0.19.0 spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb