Sha256: 4dd46f4728d2d375e8b9da7ddd8d93a0dc5ed50f4e7ce5a3427e4d569293b491
Contents?: true
Size: 1.73 KB
Versions: 6
Compression:
Stored size: 1.73 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('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('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
6 entries across 6 versions & 1 rubygems