Sha256: 69dd4dd173813eea45f21e5f3120b8b24fc3f6469645ab5d91c36998952c9c1c

Contents?: true

Size: 1.67 KB

Versions: 8

Compression:

Stored size: 1.67 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::SingleLineMethods, :config do
  subject(:cop) { described_class.new(config) }
  let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }

  it 'registers an offence for a single-line method' do
    inspect_source(cop,
                   ['def some_method; body end',
                    'def link_to(name, url); {:name => name}; end',
                    'def @table.columns; super; end'])
    expect(cop.messages).to eq(
      ['Avoid single-line method definitions.'] * 3)
  end

  context 'when AllowIfMethodIsEmpty is disabled' do
    let(:cop_config) { { 'AllowIfMethodIsEmpty' => false } }

    it 'registers an offence for an empty method' do
      inspect_source(cop, ['def no_op; end',
                           'def self.resource_class=(klass); end',
                           'def @table.columns; end'])
      expect(cop.offences.size).to eq(3)
    end
  end

  context 'when AllowIfMethodIsEmpty is enabled' do
    let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }

    it 'accepts a single-line empty method' do
      inspect_source(cop, ['def no_op; end',
                           'def self.resource_class=(klass); end',
                           'def @table.columns; end'])
      expect(cop.offences).to be_empty
    end
  end

  it 'accepts a multi-line method' do
    inspect_source(cop, ['def some_method',
                         '  body',
                         'end'])
    expect(cop.offences).to be_empty
  end

  it 'does not crash on an method with a capitalized name' do
    inspect_source(cop, ['def NoSnakeCase',
                         'end'])
    expect(cop.offences).to be_empty
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.16.0 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/single_line_methods_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/single_line_methods_spec.rb