Sha256: 8c9e05c59f51a050329d70212b3cfdcb914b95985d560f9d73d5ca71b0b55a0d

Contents?: true

Size: 1.74 KB

Versions: 11

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::MethodCallParentheses, :config do
  subject(:cop) { described_class.new(config) }
  let(:config) do
    RuboCop::Config.new('Style/EmptyLiteral' => { 'Enabled' => true })
  end

  it 'registers an offense for parens in method call without args' do
    inspect_source(cop, ['top.test()'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts parentheses for methods starting with an upcase letter' do
    inspect_source(cop, ['Test()'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts no parens in method call without args' do
    inspect_source(cop, ['top.test'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts parens in method call with args' do
    inspect_source(cop, ['top.test(a)'])
    expect(cop.offenses).to be_empty
  end

  it 'auto-corrects by removing unneeded braces' do
    new_source = autocorrect_source(cop, 'test()')
    expect(new_source).to eq('test')
  end

  it 'does not auto-correct calls that will be changed to empty literals' do
    original = ['Hash.new()',
                'Array.new()',
                'String.new()']
    new_source = autocorrect_source(cop, original)
    expect(new_source).to eq(original.join("\n"))
  end

  context 'when EmptyLiteral is disabled' do
    let(:config) do
      RuboCop::Config.new('Style/EmptyLiteral' => { 'Enabled' => false })
    end

    it 'auto-corrects calls that could be empty literals' do
      original = ['Hash.new()',
                  'Array.new()',
                  'String.new()']
      new_source = autocorrect_source(cop, original)
      expect(new_source).to eq(['Hash.new',
                                'Array.new',
                                'String.new'].join("\n"))
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

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