Sha256: c2bcf727fd0f21bc5afebde30919e9cd44722b15ccba19a5cf98c65a07c2558d

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe RedundantBegin do
        let(:cop) { RedundantBegin.new }

        it 'reports an offence for def with redundant begin block' do
          src = ['def func',
                 '  begin',
                 '    ala',
                 '  rescue => e',
                 '    bala',
                 '  end',
                 'end']
          inspect_source(cop, src)
          expect(cop.offences).to have(1).item
        end

        it 'reports an offence for defs with redundant begin block' do
          src = ['def Test.func',
                 '  begin',
                 '    ala',
                 '  rescue => e',
                 '    bala',
                 '  end',
                 'end']
          inspect_source(cop, src)
          expect(cop.offences).to have(1).item
        end

        it 'accepts a def with required begin block' do
          src = ['def func',
                 '  begin',
                 '    ala',
                 '  rescue => e',
                 '    bala',
                 '  end',
                 '  something',
                 'end']
          inspect_source(cop, src)
          expect(cop.offences).to be_empty
        end

        it 'accepts a defs with required begin block' do
          src = ['def Test.func',
                 '  begin',
                 '    ala',
                 '  rescue => e',
                 '    bala',
                 '  end',
                 '  something',
                 'end']
          inspect_source(cop, src)
          expect(cop.offences).to be_empty
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.10.0 spec/rubocop/cops/style/redundant_begin_spec.rb