Sha256: 81c6e67a38fbd4d09a5ee8e640d7c6c6ef286d9d0e2ce52390532ce7e5f8a687

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Lint
      describe EnsureReturn do
        let(:cop) { EnsureReturn.new }

        it 'registers an offence for return in ensure' do
          inspect_source(cop,
                         ['begin',
                          '  something',
                          'ensure',
                          '  file.close',
                          '  return',
                          'end'])
          expect(cop.offences).to have(1).item
        end

        it 'does not register an offence for return outside ensure' do
          inspect_source(cop,
                         ['begin',
                          '  something',
                          '  return',
                          'ensure',
                          '  file.close',
                          'end'])
          expect(cop.offences).to be_empty
        end

        it 'does not check when ensure block has no body' do
          expect do
            inspect_source(cop,
                           ['begin',
                            '  something',
                            'ensure',
                            'end'])
          end.to_not raise_exception
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.10.0 spec/rubocop/cops/lint/ensure_return_spec.rb