Sha256: 113e8a8c4e8e660101a9db657da6b825151f5420dfe2ef3b51827b9764aa8f41

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Metrics::ParameterLists, :config do
  subject(:cop) { described_class.new(config) }
  let(:cop_config) do
    {
      'Max' => 4,
      'CountKeywordArgs' => true
    }
  end

  it 'registers an offense for a method def with 5 parameters' do
    inspect_source(cop, ['def meth(a, b, c, d, e)',
                         'end'])
    expect(cop.offenses.size).to eq(1)
    expect(cop.config_to_allow_offenses).to eq('Max' => 5)
  end

  it 'accepts a method def with 4 parameters' do
    inspect_source(cop, ['def meth(a, b, c, d)',
                         'end'])
    expect(cop.offenses).to be_empty
  end

  context 'When CountKeywordArgs is true' do
    it 'counts keyword arguments as well', ruby: 2.0 do
      inspect_source(cop, ['def meth(a, b, c, d: 1, e: 2)',
                           'end'])
      expect(cop.offenses.size).to eq(1)
    end
  end

  context 'When CountKeywordArgs is false' do
    before { cop_config['CountKeywordArgs'] = false }

    it 'it does not count keyword arguments', ruby: 2.0 do
      inspect_source(cop, ['def meth(a, b, c, d: 1, e: 2)',
                           'end'])
      expect(cop.offenses).to be_empty
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.28.0 spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.27.1 spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.27.0 spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.26.1 spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.26.0 spec/rubocop/cop/metrics/parameter_lists_spec.rb
rubocop-0.25.0 spec/rubocop/cop/metrics/parameter_lists_spec.rb