Sha256: 2289da64b6f954f8e75bd9bfeb0a16ba302bfcfd890aeb221dd91716a9393425

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Lint::EnsureReturn do
  subject(:cop) { described_class.new }

  it 'registers an offense for return in ensure' do
    inspect_source(cop,
                   ['begin',
                    '  something',
                    'ensure',
                    '  file.close',
                    '  return',
                    'end'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'does not register an offense for return outside ensure' do
    inspect_source(cop,
                   ['begin',
                    '  something',
                    '  return',
                    'ensure',
                    '  file.close',
                    'end'])
    expect(cop.offenses).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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/lint/ensure_return_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.29.1 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.29.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.28.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.27.1 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.27.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.26.1 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.26.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.25.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.24.1 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.24.0 spec/rubocop/cop/lint/ensure_return_spec.rb
rubocop-0.23.0 spec/rubocop/cop/lint/ensure_return_spec.rb